home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-04d.zip / 04d / CHIP / Nero / Exact Audio Copy 0.95 / eac-0.95b4.exe / WME9.vbs < prev   
Text File  |  2003-04-01  |  111KB  |  3,670 lines

  1. 'The build number is 9.00.2980
  2. '********************************************************************************************************
  3. '
  4. ' Microsoft Windows Media
  5. ' Copyright (C) Microsoft Corporation. All rights reserved.
  6. '
  7. ' FileName:            WME9.VBS
  8. '
  9. ' Abstract:            Windows Media Command Line Script Utility with expanded support for media metadata
  10. '                       Modified by AlexZam
  11. '                      Use Cscript.exe wmcmd.vbs /? for Help
  12. '
  13. '********************************************************************************************************
  14.  
  15. Option Explicit
  16.  
  17. ' Check to see if script is run within cscript host.
  18. if instr( LCase(WScript.Fullname),"cscript.exe" ) = 0 then
  19.     WshShell.Popup "This script must be run using cscript.exe from a command window." , 0 , "Windows Media Encoder Command Script" , 64
  20.     WScript.Quit()
  21. end if
  22.  
  23. ' These variables are part of encoder idl. However vbs cannot use them directly. So these are redefined
  24. dim WMENC_ENCODER_STARTING
  25. dim WMENC_ENCODER_RUNNING
  26. dim WMENC_ENCODER_PAUSED
  27. dim WMENC_ENCODER_STOPPING
  28. dim WMENC_ENCODER_STOPPED
  29. dim WMENC_ENCODER_END_PREPROCESS
  30.  
  31. dim WMENC_ARCHIVE_LOCAL
  32. dim WMENC_ARCHIVE_RUNNING
  33. dim WMENC_ARCHIVE_PAUSED
  34. dim WMENC_ARCHIVE_STOPPED
  35.  
  36. dim WMENC_AUDIO
  37. dim WMENC_VIDEO
  38. dim WMENC_SCRIPT
  39. dim WMENC_FILETRANSFER
  40.  
  41. dim WMENC_SOURCE_START
  42. dim WMENC_SOURCE_STOP
  43. dim WMENC_SOURCE_PREPARE
  44. dim WMENC_SOURCE_UNPREPARE
  45. dim WMENC_START_FILETRANSFER
  46. dim WMENC_STOP_FILETRANSFER
  47.  
  48. dim WMENC_PROTOCOL_HTTP
  49. dim WMENC_PROTOCOL_PUSH_DISTRIBUTION
  50.  
  51. dim WMENC_PVM_NONE
  52. dim WMENC_PVM_PEAK
  53. dim WMENC_PVM_UNCONSTRAINED
  54. dim WMENC_PVM_BITRATE_BASED
  55.  
  56. dim WMA9STD_FOURCC
  57. dim WMA9PRO_FOURCC
  58. dim WMA9LSL_FOURCC
  59. dim WMSPEECH_FOURCC
  60. dim PCM_FOURCC
  61.  
  62. dim WMV7_FOURCC
  63. dim WMV8_FOURCC
  64. dim WMV9_FOURCC
  65. dim WMS9_FOURCC
  66. dim MP41_FOURCC
  67. dim UNCOMP_FOURCC
  68.  
  69. dim WMA9STD
  70. dim WMA9PRO
  71. dim WMA9LSL
  72. dim WMSPEECH
  73. dim PCM
  74.  
  75. dim WMV7
  76. dim WMV8
  77. dim WMV9
  78. dim WMS9
  79. dim MP41
  80. dim UNCOMP
  81.  
  82. dim WMENC_CONTENT_ONE_AUDIO
  83. dim WMENC_CONTENT_ONE_VIDEO
  84. dim WMENC_CONTENT_ONE_AUDIO_ONE_VIDEO
  85.  
  86. dim WMENC_VIDEO_STANDARD
  87. dim WMENC_VIDEO_DEINTERLACE
  88. dim WMENC_VIDEO_INVERSETELECINE
  89. dim WMENC_VIDEO_PROCESS_INTERLACED
  90. dim WMENC_VIDEO_TELECINE_AUTO
  91. dim WMENC_VIDEO_TELECINE_AA_TOP
  92. dim WMENC_VIDEO_TELECINE_BB_TOP
  93. dim WMENC_VIDEO_TELECINE_BC_TOP
  94. dim WMENC_VIDEO_TELECINE_CD_TOP
  95. dim WMENC_VIDEO_TELECINE_DD_TOP
  96. dim WMENC_VIDEO_TELECINE_AA_BOTTOM
  97. dim WMENC_VIDEO_TELECINE_BB_BOTTOM
  98. dim WMENC_VIDEO_TELECINE_BC_BOTTOM
  99. dim WMENC_VIDEO_TELECINE_CD_BOTTOM
  100. dim WMENC_VIDEO_TELECINE_DD_BOTTOM
  101. dim WMENC_VIDEO_INTERLACED_AUTO
  102. dim WMENC_VIDEO_INTERLACED_TOP_FIRST
  103. dim WMENC_VIDEO_INTERLACED_BOTTOM_FIRST
  104. dim WMENC_PIXELFORMAT_IYUV
  105. dim WMENC_PIXELFORMAT_I420
  106. dim WMENC_PIXELFORMAT_YV12
  107. dim WMENC_PIXELFORMAT_YUY2
  108. dim WMENC_PIXELFORMAT_UYVY
  109. dim WMENC_PIXELFORMAT_YVYU
  110. dim WMENC_PIXELFORMAT_YVU9
  111. dim WMENC_PIXELFORMAT_RGB24
  112. dim WMENC_PIXELFORMAT_RGB32
  113. dim WMENC_PIXELFORMAT_RGB555
  114. dim WMENC_PIXELFORMAT_RGB565
  115. dim WMENC_PIXELFORMAT_RGB8
  116.  
  117. WMENC_ENCODER_STARTING = 1
  118. WMENC_ENCODER_RUNNING = 2
  119. WMENC_ENCODER_PAUSED = 3
  120. WMENC_ENCODER_STOPPING = 4
  121. WMENC_ENCODER_STOPPED = 5
  122. WMENC_ENCODER_END_PREPROCESS = 6
  123.  
  124. WMENC_ARCHIVE_LOCAL = 1
  125.  
  126. WMENC_ARCHIVE_RUNNING = 1
  127. WMENC_ARCHIVE_PAUSED = 2
  128. WMENC_ARCHIVE_STOPPED = 3
  129.  
  130. WMENC_AUDIO = 1
  131. WMENC_VIDEO = 2
  132. WMENC_SCRIPT = 4
  133. WMENC_FILETRANSFER = 8
  134.  
  135. WMENC_SOURCE_START = 1
  136. WMENC_SOURCE_STOP = 2
  137. WMENC_SOURCE_PREPARE = 3
  138. WMENC_SOURCE_UNPREPARE = 4
  139. WMENC_START_FILETRANSFER = 5
  140. WMENC_STOP_FILETRANSFER = 6
  141.  
  142. WMENC_PROTOCOL_HTTP = 1
  143. WMENC_PROTOCOL_PUSH_DISTRIBUTION = 2
  144.  
  145. WMENC_PVM_NONE = 1
  146. WMENC_PVM_PEAK = 2
  147. WMENC_PVM_UNCONSTRAINED = 3
  148. WMENC_PVM_BITRATE_BASED = 4
  149.  
  150. WMA9STD_FOURCC = 353
  151. WMA9PRO_FOURCC = 354
  152. WMA9LSL_FOURCC = 355
  153. WMSPEECH_FOURCC = 10
  154. PCM_FOURCC = 0
  155.  
  156. WMV7_FOURCC = 827739479
  157. WMV8_FOURCC = 844516695
  158. WMV9_FOURCC = 861293911
  159. WMS9_FOURCC = 844321613
  160. MP41_FOURCC = 1395937357
  161. UNCOMP_FOURCC = 0
  162.  
  163. WMA9STD = "WMA9STD"
  164. WMA9PRO = "WMA9PRO"
  165. WMA9LSL = "WMA9LSL"
  166. WMSPEECH = "WMSP9"
  167. PCM = "PCM"
  168.  
  169. WMV7 = "WMV7"
  170. WMV8 = "WMV8"
  171. WMV9 = "WMV9"
  172. WMS9 = "WMS9"
  173. MP41 = "MP41"
  174. UNCOMP = "UNCOMP"
  175.  
  176. WMENC_CONTENT_ONE_AUDIO = 1
  177. WMENC_CONTENT_ONE_VIDEO = 16
  178. WMENC_CONTENT_ONE_AUDIO_ONE_VIDEO = 17
  179.  
  180. WMENC_VIDEO_STANDARD = 1
  181. WMENC_VIDEO_DEINTERLACE = 2
  182. WMENC_VIDEO_INVERSETELECINE = 3
  183. WMENC_VIDEO_PROCESS_INTERLACED = 4
  184. WMENC_VIDEO_TELECINE_AA_TOP = &H23
  185. WMENC_VIDEO_TELECINE_BB_TOP = &H33
  186. WMENC_VIDEO_TELECINE_BC_TOP = &H43
  187. WMENC_VIDEO_TELECINE_CD_TOP = &H53
  188. WMENC_VIDEO_TELECINE_DD_TOP = &H63
  189. WMENC_VIDEO_TELECINE_AA_BOTTOM = &H73
  190. WMENC_VIDEO_TELECINE_BB_BOTTOM = &H83
  191. WMENC_VIDEO_TELECINE_BC_BOTTOM = &H93
  192. WMENC_VIDEO_TELECINE_CD_BOTTOM = &HA3
  193. WMENC_VIDEO_TELECINE_DD_BOTTOM = &HB3
  194. WMENC_VIDEO_INTERLACED_AUTO = 4
  195. WMENC_VIDEO_INTERLACED_TOP_FIRST = &H2004
  196. WMENC_VIDEO_INTERLACED_BOTTOM_FIRST = &H3004
  197.  
  198. WMENC_PIXELFORMAT_IYUV = &H56555949
  199. WMENC_PIXELFORMAT_I420 = &H30323449
  200. WMENC_PIXELFORMAT_YV12 = &H32315659
  201. WMENC_PIXELFORMAT_YUY2 = &H32595559
  202. WMENC_PIXELFORMAT_UYVY = &H59565955
  203. WMENC_PIXELFORMAT_YVYU = &H55595659
  204. WMENC_PIXELFORMAT_YVU9 = &H39555659
  205. WMENC_PIXELFORMAT_RGB24 = &HE436EB7D
  206. WMENC_PIXELFORMAT_RGB32 = &HE436EB7E
  207. WMENC_PIXELFORMAT_RGB555 = &HE436EB7C
  208. WMENC_PIXELFORMAT_RGB565 = &HE436EB7B
  209. WMENC_PIXELFORMAT_RGB8 = &HE436EB7A
  210.  
  211. dim g_strInput
  212. dim g_strOutput
  213. dim g_strOutputString
  214. dim g_intSessionType
  215. dim g_strProfile
  216. dim g_strAlbum
  217. dim g_strGenre
  218. dim g_strTitle
  219. dim g_intTrackNo
  220. dim g_strYear
  221. dim g_strAuthor
  222. dim g_strCopyright
  223. dim g_strDescription
  224. dim g_strRating
  225. dim g_strWMEFile
  226. dim g_strProfileSave
  227. dim g_strProfileLoad
  228.  
  229. dim g_intAudioDevice
  230. dim g_intVideoDevice
  231. dim g_intProfile
  232. dim g_intBroadcast
  233. dim g_strPushServer
  234. dim g_strPublishingPoint
  235. dim g_strPushTemplate
  236. dim g_intMarkInTime
  237. dim g_intMarkOutTime
  238. dim g_intDuration
  239. dim g_intVerbose
  240.  
  241. dim g_objEncoder
  242. dim g_objSourceGroup
  243. dim g_objAudioSource
  244. dim g_objVideoSource
  245. dim g_objProfile
  246. dim g_objFileSystem
  247.  
  248. dim g_blnEncoderStarted
  249. dim g_blnEndPreProcess
  250. dim g_blnEncoderStopped
  251. dim g_intErrorCode
  252. dim g_intRunningSource
  253. dim g_blnDevice
  254. dim g_blnAudioOnly
  255. dim g_blnVideoOnly
  256. dim g_blnSilent
  257.  
  258. dim g_intAudioVBRMode
  259. dim g_strAudioCodec
  260. dim g_strAudioSetting
  261. dim g_intAudioPeakBitrate
  262. dim g_intAudioPeakBuffer
  263. dim g_intAudioSpeechContent
  264. dim g_strAudioSpeechEdl
  265. dim g_intAudioSurroundMix
  266. dim g_intAudioCenterMix
  267. dim g_intAudioLEFMix
  268. dim g_strAudioCodecName
  269.  
  270. dim g_intVideoVBRMode
  271. dim g_strVideoCodec
  272. dim g_intVideoBitrate
  273. dim g_intVideoWidth
  274. dim g_intVideoHeight
  275. dim g_intVideoFramerate
  276. dim g_intVideoKeydist
  277. dim g_intVideoBuffer
  278. dim g_intVideoQuality
  279. dim g_intVideoPeakBitrate
  280. dim g_intVideoPeakBuffer
  281. dim g_intVideoPreprocess
  282. dim g_strPixelFormat
  283. dim g_intPixelAspectRatioX
  284. dim g_intPixelAspectRatioY
  285. dim g_intVideoPerformance
  286. dim g_strVideoCodecName
  287. dim g_strVideoDevConf
  288. dim g_intMaxPacketSize
  289. dim g_intMinPacketSize
  290.  
  291. dim i
  292. dim j
  293. dim g_blnCreateCustomProfile
  294.  
  295. dim g_tStartTime
  296. dim g_tStopTime
  297.  
  298. dim g_intClipLeft
  299. dim g_intClipRight
  300. dim g_intClipTop
  301. dim g_intClipBottom
  302.  
  303. g_strInput = ""
  304. g_strOutput = ""
  305. g_strOutputString = ""
  306. g_intSessionType = WMENC_CONTENT_ONE_AUDIO
  307. g_strProfile = ""
  308. g_strTitle = ""
  309. g_strAuthor = ""
  310. g_strAlbum = ""
  311. g_intTrackNo = ""
  312. g_strYear = ""
  313. g_strGenre = ""
  314. g_strCopyright = ""
  315. g_strDescription = ""
  316. g_strRating = ""
  317. g_strWMEFile = ""
  318. g_strProfileSave = ""
  319. g_strProfileLoad = ""
  320. g_strProfile = ""
  321.  
  322. g_intAudioDevice = -1
  323. g_intVideoDevice = -1
  324. g_intProfile = -1
  325. g_intBroadcast = -1
  326. g_strPushServer = ""
  327. g_strPublishingPoint = ""
  328. g_strPushTemplate = ""
  329. g_intMarkInTime = -1
  330. g_intMarkOutTime = -1
  331. g_intDuration = -1
  332. g_intVerbose = 2
  333.  
  334. g_blnEncoderStarted = false
  335. g_blnEncoderStopped = false
  336. g_blnEndPreProcess = false
  337. g_blnDevice = false
  338. g_intErrorCode = 0
  339. g_intRunningSource = 0
  340. g_blnAudioOnly = false
  341. g_blnVideoOnly = false
  342.  
  343. g_intAudioVBRMode = -1
  344. g_strAudioCodec = ""
  345. g_strAudioSetting = ""
  346. g_intAudioPeakBitrate = -1
  347. g_intAudioPeakBuffer = -1
  348. g_intAudioSpeechContent = -1
  349. g_strAudioSpeechEdl = ""
  350. g_intAudioSurroundMix = -1
  351. g_intAudioCenterMix = -1
  352. g_intAudioLEFMix = -1
  353. g_strAudioCodecName = ""
  354.  
  355. g_intVideoVBRMode = -1
  356. g_strVideoCodec = ""
  357. g_intVideoBitrate = -1
  358. g_intVideoWidth = -1
  359. g_intVideoHeight = -1
  360. g_intVideoFramerate = -1
  361. g_intVideoKeydist = -1
  362. g_intVideoBuffer = -1
  363. g_intVideoQuality = -1
  364. g_intVideoPeakBitrate = -1
  365. g_intVideoPeakBuffer = -1
  366. g_intVideoPreprocess = -1
  367. g_strPixelFormat = ""
  368. g_intPixelAspectRatioX = -1
  369. g_intPixelAspectRatioY = -1
  370. g_intVideoPerformance = -1
  371. g_strVideoCodecName = ""
  372. g_strVideoDevConf = ""
  373. g_intMaxPacketSize = -1
  374. g_intMinPacketSize = -1
  375.  
  376. g_intClipLeft = -1
  377. g_intClipRight = -1
  378. g_intClipTop = -1
  379. g_intClipBottom = -1
  380.  
  381. g_blnCreateCustomProfile = true
  382.  
  383. ' Create an encoder object.
  384. set g_objEncoder = WScript.CreateObject( "WMEncEng.WMEncoder" )
  385. WScript.ConnectObject g_objEncoder, "Encoder_"        ' Setup call back events
  386.     
  387. set g_objFileSystem = WScript.CreateObject( "Scripting.FileSystemObject" )
  388. g_objSourceGroup = Null
  389. g_objAudioSource = Null
  390. g_objVideoSource = Null
  391. g_objProfile = NULL
  392.  
  393. ' Read a integer value from the paramters list.
  394. ' args is the paramters list to be read.
  395. ' intIndex1 is the position of the parameter name.
  396. ' intIndex2 is the position of the parameter value.
  397. ' It will return the integer if it can read a integer value from the parameter list
  398. ' It will return -1 if it can not get a integer value from the paramters list.
  399. function ReadInteger( args, intIndex1, intIndex2 )
  400.     on error resume next
  401.     dim strTypeName
  402.  
  403.     ' Check the range of index.
  404.     if intIndex2 > UBound(args) or Left( args(intIndex2), 1 ) = "-" then
  405.         OutputInfo "Invalid format for parameter " & args(intIndex1)
  406.         ReadInteger = -1
  407.         exit function
  408.     end if
  409.  
  410.     strTypeName = typename( eval( args(intIndex2) ) )
  411.  
  412.     ' Convert it to an integer value.
  413.     ReadInteger = CLng( args(intIndex2) )
  414.  
  415.     ' The value is not in integer fommat.
  416.     if err.number <> 0 or ( strTypeName <> "Integer" and strTypeName <> "Long" )  then
  417.         OutputInfo "Expect integer value for parameter " & args(intIndex1)
  418.         ReadInteger = -1
  419.         err.Clear
  420.     end if
  421.  
  422. end function
  423.  
  424. ' Read a float value from the paramters list.
  425. ' args is the paramters list to be read.
  426. ' intIndex1 is the position of the parameter name.
  427. ' intIndex2 is the position of the parameter value.
  428. ' It will return the float if it can read a float value from the parameter list
  429. ' It will return -1 if it can not get a float value from the paramters list.
  430. function ReadFloat( args, intIndex1, intIndex2 )
  431.     on error resume next
  432.     dim strTypeName
  433.  
  434.     ' Check the range of index.
  435.     if intIndex2 > UBound(args) or Left( args(intIndex2), 1 ) = "-" then
  436.         OutputInfo "Invalid format for parameter " & args(intIndex1)
  437.         ReadFloat = -1
  438.         exit function
  439.     end if
  440.  
  441.     strTypeName = typename( eval( args(intIndex2) ) )
  442.  
  443.     ' Convert it to an integer value.
  444.     ReadFloat = CSng( args(intIndex2) )
  445.  
  446.     ' The value is not in integer fommat.
  447.     if err.number <> 0 or ( strTypeName <> "Integer" and strTypeName <> "Long" and strTypeName <> "Single" and strTypeName <> "Double" )  then
  448.         OutputInfo "Expect float value for parameter " & args(intIndex1)
  449.         ReadFloat = -1
  450.         err.Clear
  451.     end if
  452.  
  453. end function
  454.  
  455. ' Read a var value from the paramters list.
  456. ' args is the paramters list to be read.
  457. ' intIndex1 is the position of the parameter name.
  458. ' intIndex2 is the position of the parameter value.
  459. ' It will return the var if it can not get a var value from the paramters list.
  460. ' It will return "" if it can not get a var value from the paramters list.
  461. function ReadString( args, intIndex1, intIndex2 )
  462.     ' Check the range of index.
  463.     if intIndex2 > UBound(args) or Left( args(intIndex2), 1 ) = "-" then
  464.         OutputInfo "Invalid format for parameter " & args(intIndex1)
  465.         ReadString = ""
  466.         exit function
  467.     end if
  468.  
  469.     ReadString = args(intIndex2)
  470. end function
  471.  
  472. function ConvertStringToInteger( strInput )
  473.     on error resume next
  474.     dim strTypeName
  475.  
  476.     strTypeName = typename( eval( strInput ) )
  477.  
  478.     ' Convert it to an integer value.
  479.     ConvertStringToInteger = CLng( strInput )
  480.  
  481.     ' The value is not in integer fommat.
  482.     if err.number <> 0 or ( strTypeName <> "Integer" and strTypeName <> "Long" )  then
  483.         OutputInfo "Invalid format " & strInput & " expecting integer value"
  484.         ConvertStringToInteger = -1
  485.         err.Clear
  486.     end if
  487.  
  488. end function
  489.  
  490. ' Parse parameters.
  491.  
  492. if wscript.arguments.Length = 0 then
  493.     ShowHelp()
  494.     wscript.quit()
  495. end if
  496.  
  497. dim colStrArgs()
  498. reDim colStrArgs( wscript.arguments.Length-1 )
  499. for i = 0 to wscript.arguments.Length-1
  500.     colStrArgs(i) = wscript.arguments(i)
  501. next
  502.  
  503. if ParseParameters( colStrArgs ) then
  504.     ' Do different things depending on whether input is wme, directory encoding or file encoding
  505.     if g_strInput <> "" and g_objFileSystem.FolderExists(g_strInput) then
  506.         DoDirectoryModeEncoding()
  507.     elseif SetupEncoder() then
  508.         ' Transcode and show statistics information
  509.         if Transcode() and not g_blnSilent then 
  510.             ShowStatistics()
  511.         end if 
  512.     end if
  513. end if
  514.  
  515. WScript.Quit()
  516.  
  517. ' Output information
  518. function OutputInfo( strInfo )
  519.     WScript.Echo( strInfo )
  520. end function
  521.  
  522. ' Event handler for encoder state
  523. function Encoder_OnStateChange( enumState )
  524.     dim strState
  525.     ' Translate encoder state
  526.     select case  enumState
  527.         case WMENC_ENCODER_STARTING
  528.             strState = "Starting"
  529.  
  530.         case WMENC_ENCODER_RUNNING
  531.             strState = "Running"
  532.             g_blnEncoderStarted = true
  533.  
  534.         case WMENC_ENCODER_PAUSED
  535.             strState = "Paused"
  536.  
  537.         case WMENC_ENCODER_STOPPING
  538.             strState = "Stopping"
  539.  
  540.         case WMENC_ENCODER_STOPPED
  541.             g_tStopTime = Now()
  542.             strState = "Stopped"
  543.             g_blnEncoderStopped = true
  544.  
  545.         case WMENC_ENCODER_END_PREPROCESS
  546.             strState = "End Preprorocess"
  547.             g_blnEndPreProcess = true
  548.  
  549.         case else
  550.             strState = "Unknown State"
  551.     end select
  552.  
  553.     Encoder_OnStateChange = 1
  554. end function
  555.  
  556. ' Event handler for encoder error
  557. function Encoder_OnError( intResult )
  558.     g_intErrorCode = intResult
  559.  
  560.     Encoder_OnError = 0
  561. end function
  562.  
  563. ' Parse the parameters of this program.
  564. function ParseParameters( args )
  565.     dim strMarkOutTime
  566.     dim strArguments
  567.     dim strSaveToCfgFile
  568.     dim strLoadFromCfgFile
  569.     dim strCfgFileArguments
  570.     dim colStrConfigArgs
  571.     dim objTextFile
  572.  
  573.     for i=0 to UBound(args)
  574.         if args(i) = "-s_config" then
  575.             i = i + 1
  576.         else
  577.             strArguments = strArguments & args(i) & " "
  578.         end if
  579.  
  580.         if args(i) = "-config" then
  581.             strLoadFromCfgFile = ReadString( args, i, i+1 )
  582.             if strLoadFromCfgFile = "" then
  583.                 ParseParameters = false
  584.                 exit function
  585.             end if
  586.         
  587.             i = i + 1
  588.  
  589.             strLoadFromCfgFile = g_objFileSystem.GetAbsolutePathName( strLoadFromCfgFile )
  590.             set objTextFile = g_objFileSystem.OpenTextFile( strLoadFromCfgFile, 1 )
  591.             strCfgFileArguments = objTextFile.ReadLine
  592.             objTextFile.Close
  593.             
  594.             strCfgFileArguments = Trim( strCfgFileArguments )
  595.             if strCfgFileArguments = "" then
  596.                 OutputInfo "Configuration file " & strLoadFromCfgFile & " is empty"
  597.                 ParseParameters = false
  598.                 exit function
  599.             end if
  600.             colStrConfigArgs = Split( strCfgFileArguments )
  601.             if ParseParameters( colStrConfigArgs ) = false then
  602.                 ParseParameters = false
  603.                 exit function
  604.             end if
  605.         end if
  606.     next
  607.  
  608.     ' OutputInfo "Args = " & strArguments
  609.  
  610.     if UBound(args) = 0 then
  611.         ' If it has only has one parameter, check the content of this parameter.
  612.         select case LCase( args(0) )     
  613.             case "-devices":
  614.                 ' List all audio and video devices.
  615.                 ListDevices()
  616.                 ParseParameters = false
  617.                 exit function
  618.  
  619.             case "-a_codecs":
  620.                 ' List all audio codecs.
  621.                 ListAudioCodecs()
  622.                 ParseParameters = false
  623.                 exit function
  624.  
  625.             case "-a_formats"
  626.                 ' List audio formats
  627.                 ListAudioFormats()
  628.                 ParseParameters = false
  629.                 exit function
  630.             
  631.             case "-v_codecs":
  632.                 ' List all video codecs.
  633.                 ListVideoCodecs()
  634.                 ParseParameters = false
  635.                 exit function
  636.             
  637.             case "-help":
  638.                 ' Show help information.
  639.                 ShowHelp()
  640.                 ParseParameters = false
  641.                 exit function
  642.  
  643.             case "-?":
  644.                 ' Show help information.
  645.                 ShowHelp()
  646.                 ParseParameters = false
  647.                 exit function
  648.  
  649.             case "-all?":
  650.                 ' Show help information.
  651.                 ShowHelp()
  652.                 ParseParameters = false
  653.                 exit function
  654.             
  655.             case "/?":
  656.                 ' Show help information.
  657.                 ShowHelp()
  658.                 ParseParameters = false
  659.                 exit function
  660.             
  661.             case "-help?"
  662.                 ' Being up the encoder util chm
  663.                 ShowHelpChm()
  664.                 ParseParameters = false
  665.                 exit function
  666.  
  667.         end select
  668.     end if
  669.  
  670.     if UBound(args) = 1 then
  671.         select case LCase( args(0) ) 
  672.             case "-input"
  673.             ' Print out info about file specified
  674.             g_strInput = ReadString( args, 0, 1 )
  675.             if g_strInput = ""  then
  676.                 ParseParameters = false
  677.                 exit function
  678.             end if
  679.  
  680.             PrintFileInfo()
  681.             ParseParameters = false
  682.             exit function
  683.         end select
  684.     end if
  685.  
  686.     ' Check all parameters.
  687.     for i=0 to UBound(args)
  688.     
  689.         select case LCase( args(i) )
  690.             ' Parse all input related stuff
  691.             case "-wme"
  692.                 ' Get the WME file name to be load.
  693.                 g_strWMEFile = ReadString( args, i, i+1 )
  694.                 if g_strWMEFile = "" then
  695.                     ParseParameters = false
  696.                     exit function
  697.                 end if
  698.         
  699.                 i = i + 1
  700.  
  701.             case "-input"                        
  702.                 ' Get input source file name.
  703.                 g_strInput = ReadString( args, i, i+1 )
  704.                 if g_strInput = ""  then
  705.                     ParseParameters = false
  706.                     exit function
  707.                 end if
  708.         
  709.                 i = i + 1
  710.  
  711.             case "-audioonly"
  712.                 g_blnAudioOnly = true
  713.  
  714.             case "-videoonly"
  715.                 g_blnVideoOnly = true
  716.  
  717.             case "-adevice"
  718.                 g_blnDevice = true
  719.                 ' Get audio device index.
  720.                 if i+1 <= UBound(args) and Left( args(i+1), 1 ) <> "-" then
  721.                     g_intAudioDevice = ReadInteger( args, i, i+1 )
  722.                     if g_intAudioDevice = -1 then
  723.                         ParseParameters = false
  724.                         exit function
  725.                     end if
  726.                     
  727.                     i = i + 1
  728.                 else
  729.                     g_intAudioDevice = 0     ' default audio device
  730.                 end if
  731.  
  732.             case "-vdevice"
  733.                 g_blnDevice = true
  734.                 ' Get video device index.
  735.                 if i+1 <= UBound(args) and Left( args(i+1), 1 ) <> "-" then
  736.                     g_intVideoDevice = ReadInteger( args, i, i+1 )
  737.                     if g_intVideoDevice = -1 then
  738.                         ParseParameters = false
  739.                         exit function
  740.                     end if
  741.                 
  742.                     i = i + 1
  743.                 else
  744.                     g_intVideoDevice = 0     ' default video device
  745.                 end if
  746.  
  747.             ' Parse all profile related stuff
  748.             case "-profile"
  749.                 ' Get input source file name.
  750.                 g_strProfile = ReadString( args, i, i+1 )
  751.                 if g_strProfile = ""  then
  752.                     ParseParameters = false
  753.                     exit function
  754.                 end if
  755.         
  756.                 i = i + 1
  757.  
  758.             ' Parse audio related stuff
  759.             case "-a_mode"
  760.                 g_intAudioVBRMode = ReadInteger( args, i, i+1 )
  761.                 if g_intAudioVBRMode = -1 then
  762.                     ParseParameters = false
  763.                     exit function
  764.                 end if
  765.         
  766.                 i = i + 1
  767.  
  768.             case "-a_codec"
  769.                 'Get audio codec name
  770.                 g_strAudioCodec = ReadString( args, i, i+1 )
  771.                 g_strAudioCodec = UCase( g_strAudioCodec )
  772.  
  773.                 if g_strAudioCodec <> WMA9STD and g_strAudioCodec <> WMA9PRO and g_strAudioCodec <> WMA9LSL and g_strAudioCodec <> WMSPEECH and g_strAudioCodec <> PCM then
  774.                     OutputInfo "Please enter correct audio codec index only"
  775.                     ParseParameters = false
  776.                     exit function
  777.                 end if
  778.  
  779.                 if g_strAudioCodec = ""  then
  780.                     ParseParameters = false
  781.                     exit function
  782.                 end if
  783.         
  784.                 i = i + 1
  785.  
  786.             case "-a_setting"
  787.                 'Get audio setting
  788.                 g_strAudioSetting = ReadString( args, i, i+1 )
  789.                 if g_strAudioSetting = ""  then
  790.                     ParseParameters = false
  791.                     exit function
  792.                 end if
  793.         
  794.                 i = i + 1
  795.  
  796.             case "-a_peakbitrate"
  797.                 'Get audio peakbitrate size
  798.                 g_intAudioPeakBitrate = ReadInteger( args, i, i+1 )
  799.                 if g_intAudioPeakBitrate = -1  then
  800.                     ParseParameters = false
  801.                     exit function
  802.                 end if
  803.         
  804.                 i = i + 1
  805.  
  806.             case "-a_peakbuffer"
  807.                 'Get audio peakbuffer size
  808.                 g_intAudioPeakBuffer = ReadInteger( args, i, i+1 )
  809.                 if g_intAudioPeakBuffer = -1  then
  810.                     ParseParameters = false
  811.                     exit function
  812.                 end if
  813.         
  814.                 i = i + 1
  815.  
  816.             case "-a_content"
  817.                 'Get content type for speech
  818.                 g_intAudioSpeechContent = ReadInteger( args, i, i+1 )
  819.                 if g_intAudioSpeechContent = -1 then
  820.                     ParseParameters = false
  821.                     exit function
  822.                 elseif g_intAudioSpeechContent < 0 or g_intAudioSpeechContent > 2 then
  823.                     OutputInfo "Invalid range for parameter " & args(i)
  824.                     ParseParameters = false
  825.                     exit function
  826.                 end if
  827.         
  828.                 i = i + 1
  829.  
  830.             case "-a_contentedl"
  831.                 'Get EDL file for speech content
  832.                 g_strAudioSpeechEdl = ReadString( args, i, i+1 )
  833.                 if g_strAudioSpeechEdl = ""  then
  834.                     ParseParameters = false
  835.                     exit function
  836.                 end if
  837.         
  838.                 i = i + 1
  839.  
  840.             case "-a_folddown6to2"
  841.                 'Get EDL file for speech content
  842.                 g_intAudioSurroundMix = ReadInteger( args, i, i+1 )
  843.                 if g_intAudioSurroundMix = -1  then
  844.                     ParseParameters = false
  845.                     exit function
  846.                 end if
  847.                 g_intAudioCenterMix = ReadInteger( args, i, i+2 )
  848.                 if g_intAudioCenterMix = -1  then
  849.                     ParseParameters = false
  850.                     exit function
  851.                 end if    
  852.                 g_intAudioLEFMix = ReadInteger( args, i, i+3 )
  853.                 if g_intAudioLEFMix = -1  then
  854.                     ParseParameters = false
  855.                     exit function
  856.                 end if
  857.         
  858.                 i = i + 3
  859.  
  860.             ' Parse video related stuff
  861.             case "-v_mode"
  862.                 g_intVideoVBRMode = ReadInteger( args, i, i+1 )
  863.                 if g_intVideoVBRMode = -1 then
  864.                     ParseParameters = false
  865.                     exit function
  866.                 end if
  867.         
  868.                 i = i + 1
  869.  
  870.             case "-v_codec"
  871.                 'Get video codec name
  872.                 g_strVideoCodec = ReadString( args, i, i+1 )
  873.                 g_strVideoCodec = UCase( g_strVideoCodec )
  874.                 if g_strVideoCodec <> WMV7 and g_strVideoCodec <> WMV8 and g_strVideoCodec <> WMV9 and g_strVideoCodec <> WMS9 and g_strVideoCodec <> MP41 and g_strVideoCodec <> UNCOMP then
  875.                     OutputInfo "Please enter correct video codec index only"
  876.                     ParseParameters = false
  877.                     exit function
  878.                 end if
  879.  
  880.                 if g_strVideoCodec = ""  then
  881.                     ParseParameters = false
  882.                     exit function
  883.                 end if
  884.         
  885.                 i = i + 1
  886.  
  887.             case "-v_bitrate"
  888.                 'Get video bitrate
  889.                 g_intVideoBitrate = ReadInteger( args, i, i+1 )
  890.                 if g_intVideoBitrate = -1  then
  891.                     ParseParameters = false
  892.                     exit function
  893.                 end if
  894.         
  895.                 i = i + 1
  896.  
  897.             case "-v_buffer"
  898.                 'Get video buffer
  899.                 g_intVideoBuffer = ReadInteger( args, i, i+1 )
  900.                 if g_intVideoBuffer = -1  then
  901.                     ParseParameters = false
  902.                     exit function
  903.                 end if
  904.         
  905.                 i = i + 1
  906.  
  907.             case "-v_width"
  908.                 'Get video width
  909.                 g_intVideoWidth = ReadInteger( args, i, i+1 )
  910.                 if g_intVideoWidth = -1  then
  911.                     ParseParameters = false
  912.                     exit function
  913.                 end if
  914.         
  915.                 i = i + 1
  916.  
  917.             case "-v_height"
  918.                 'Get video height
  919.                 g_intVideoHeight = ReadInteger( args, i, i+1 )
  920.                 if g_intVideoHeight = -1  then
  921.                     ParseParameters = false
  922.                     exit function
  923.                 end if
  924.         
  925.                 i = i + 1
  926.  
  927.             case "-v_framerate"
  928.                 'Get video framerate
  929.                 g_intVideoFramerate = ReadFloat( args, i, i+1 )
  930.                 if g_intVideoFramerate = -1  then
  931.                     ParseParameters = false
  932.                     exit function
  933.                 end if
  934.                 g_intVideoFramerate = 1000 * g_intVideoFramerate
  935.         
  936.                 i = i + 1
  937.  
  938.             case "-v_keydist"
  939.                 'Get video keyframe distance
  940.                 g_intVideoKeydist = ReadInteger( args, i, i+1 )
  941.                 if g_intVideoKeydist = -1  then
  942.                     ParseParameters = false
  943.                     exit function
  944.                 end if
  945.  
  946.                 g_intVideoKeydist = 1000 * g_intVideoKeydist
  947.         
  948.                 i = i + 1
  949.  
  950.             case "-v_quality"
  951.                 'Get video bufferwindow size
  952.                 g_intVideoQuality = ReadInteger( args, i, i+1 )
  953.                 if g_intVideoQuality = -1  then
  954.                     ParseParameters = false
  955.                     exit function
  956.                 end if
  957.         
  958.                 i = i + 1
  959.  
  960.             case "-v_peakbitrate"
  961.                 'Get video peakbitrate size
  962.                 g_intVideoPeakBitrate = ReadInteger( args, i, i+1 )
  963.                 if g_intVideoPeakBitrate = -1  then
  964.                     ParseParameters = false
  965.                     exit function
  966.                 end if
  967.         
  968.                 i = i + 1
  969.  
  970.             case "-v_peakbuffer"
  971.                 'Get video peakbuffer size
  972.                 g_intVideoPeakBuffer = ReadInteger( args, i, i+1 )
  973.                 if g_intVideoPeakBuffer = -1  then
  974.                     ParseParameters = false
  975.                     exit function
  976.                 end if
  977.         
  978.                 i = i + 1
  979.  
  980.             case "-v_performance"
  981.                 'Get video complexity setting
  982.                 g_intVideoPerformance = ReadInteger( args, i, i+1 )
  983.                 if g_intVideoPerformance <> 0 and g_intVideoPerformance <> 20 and g_intVideoPerformance <> 40 and g_intVideoPerformance <> 60 and g_intVideoPerformance <> 80 and g_intVideoPerformance <> 100 then
  984.                     ParseParameters = false
  985.                     exit function
  986.                 end if
  987.  
  988.                 i = i + 1
  989.  
  990.             case "-v_preproc"
  991.                 'Get video preprocess setting
  992.                 g_intVideoPreprocess = ReadInteger( args, i, i+1 )
  993.                 if g_intVideoPreprocess = -1  or g_intVideoPreprocess > 18 then
  994.                     OutputInfo "Invalid preproc value: " & args(i+1)
  995.                     ParseParameters = false
  996.                     exit function
  997.                 end if
  998.     
  999.                 i = i + 1
  1000.  
  1001.             case "-pixelformat"
  1002.                 ' Get pixelformat.
  1003.                 g_strPixelFormat = ReadString( args, i, i+1 )
  1004.                 if g_strPixelFormat = "" then
  1005.                     ParseParameters = false
  1006.                     exit function
  1007.                 end if
  1008.         
  1009.                 i = i + 1
  1010.  
  1011.             case "-pixelratio"
  1012.                 ' Get pixelformat.
  1013.                 g_intPixelAspectRatioX = ReadInteger( args, i, i+1 )
  1014.                 g_intPixelAspectRatioY = ReadInteger( args, i, i+2 )
  1015.  
  1016.                 if g_intPixelAspectRatioX = -1 or g_intPixelAspectRatioY = -1 then
  1017.                     ParseParameters = false
  1018.                     exit function
  1019.                 end if
  1020.         
  1021.                 i = i + 2
  1022.  
  1023.             case "-v_clip"
  1024.                 ' Get clipping values.
  1025.                 g_intClipLeft   = ReadInteger( args, i, i+1 )
  1026.                 g_intClipTop    = ReadInteger( args, i, i+2 )
  1027.                 g_intClipRight  = ReadInteger( args, i, i+3 )
  1028.                 g_intClipBottom = ReadInteger( args, i, i+4 )
  1029.  
  1030.                 if g_intClipLeft = -1 or g_intClipTop = -1 or g_intClipRight = -1 or g_intClipBottom = -1 then
  1031.                     ParseParameters = false
  1032.                     exit function
  1033.                 end if
  1034.  
  1035.                 i = i + 4
  1036.  
  1037.             case "-v_profile"
  1038.                 ' Get video device conformance value
  1039.                 g_strVideoDevConf = ReadString( args, i, i+1 )
  1040.                 g_strVideoDevConf = UCase( g_strVideoDevConf )
  1041.  
  1042.                 if g_strVideoDevConf = ""  then
  1043.                     ParseParameters = false
  1044.                     exit function
  1045.                 end if
  1046.         
  1047.                 i = i + 1
  1048.  
  1049.             ' Parse all output related stuff
  1050.             case "-output"                        
  1051.                 ' Get output file name.
  1052.                 g_strOutput = ReadString( args, i, i+1 )
  1053.                 if g_strOutput = "" then
  1054.                     ParseParameters = false
  1055.                     exit function
  1056.                 end if
  1057.         
  1058.                 i = i + 1
  1059.  
  1060.             case "-outputstring"
  1061.                 ' Read in the string that is to be appended to output file name
  1062.                 g_strOutputString = ReadString( args, i, i+1 )
  1063.                 if g_strOutputString = "" then
  1064.                     ParseParameters = false
  1065.                     exit function
  1066.                 end if
  1067.         
  1068.                 i = i + 1
  1069.  
  1070.             case "-broadcast"
  1071.                 ' Get broadcast port number.
  1072.                 if i+1 <= UBound(args) and Left( args(i+1), 1 ) <> "-" then
  1073.                     g_intBroadcast = ReadInteger( args, i, i+1 )
  1074.                     if g_intBroadcast = -1 then
  1075.                         ParseParameters = false
  1076.                         exit function
  1077.                     end if
  1078.         
  1079.                     i = i + 1
  1080.                 else
  1081.                     g_intBroadcast = 8080
  1082.                 end if
  1083.  
  1084.             case "-push"
  1085.                 ' Get push server, pub point and template name (optional)
  1086.                 g_strPushServer = ReadString( args, i, i+1 )
  1087.                 g_strPublishingPoint = ReadString( args, i, i+2 )
  1088.  
  1089.                 if g_strPushServer = "" or g_strPublishingPoint = "" then
  1090.                     ParseParameters = false
  1091.                     exit function
  1092.                 end if
  1093.  
  1094.                 ' Check if template name is specified
  1095.                 if i+1 <= UBound(args) and Left( args(i+3), 1 ) <> "-" then
  1096.                     g_strPushTemplate = ReadString( args, i, i+3 )
  1097.                     i = i + 3
  1098.                 else
  1099.                     i = i + 2
  1100.                 end if
  1101.  
  1102.             case "-time"
  1103.                 ' Get the mark in time of the source file.
  1104.                 g_intMarkInTime = ReadInteger( args, i, i+1 )
  1105.  
  1106.                 ' Get the markout time of the source file
  1107.                 strMarkOutTime = ReadString( args, i, i+2 )
  1108.                 if strMarkOutTime <> "end" then
  1109.                     g_intMarkOutTime = ConvertStringToInteger( strMarkOutTime )
  1110.                 else
  1111.                     g_intMarkOutTime = 0
  1112.                 end if
  1113.  
  1114.                 if g_intMarkInTime = -1 or g_intMarkOutTime = -1 then
  1115.                     ParseParameters = false
  1116.                     exit function
  1117.                 end if
  1118.         
  1119.         
  1120.                 i = i + 2
  1121.  
  1122.             case "-duration"
  1123.                 ' Get the duration of the encoding session.
  1124.                 g_intDuration = ReadInteger( args, i, i+1 )
  1125.                 if g_intDuration = -1 then
  1126.                     ParseParameters = false
  1127.                     exit function
  1128.                 end if
  1129.         
  1130.                 i = i + 1
  1131.  
  1132.             case "-silent"
  1133.                 g_blnSilent = true
  1134.  
  1135.             ' Parse all attributes
  1136.             case "-title"
  1137.                 ' Get the title of the output file.
  1138.                 g_strTitle = ReadString( args, i, i+1 )
  1139.                 if g_strTitle = "" then
  1140.                     ParseParameters = false
  1141.                     exit function
  1142.                 end if
  1143.  
  1144.                 i = i + 1
  1145.  
  1146.             case "-author"                        
  1147.                 ' Get the author of the output file.
  1148.                 g_strAuthor = ReadString( args, i, i+1 )
  1149. '                if g_strAuthor = "" then
  1150. '                    ParseParameters = false
  1151. '                    exit function
  1152. '                end if
  1153.         
  1154.                 i = i + 1
  1155.  
  1156.             case "-album"                        
  1157.                 ' Get the album of the output file.
  1158.                 g_strAlbum = ReadString( args, i, i+1 )
  1159. '                if g_strAlbum = "" then
  1160. '                    ParseParameters = false
  1161. '                    exit function
  1162. '                end if
  1163.         
  1164.                 i = i + 1
  1165.  
  1166.             case "-trackno"                        
  1167.                 ' Get the track number of the output file.
  1168.                 g_intTrackNo = ReadString( args, i, i+1 )
  1169. '                if (g_intTrackNo = "") or (!IsNumeric(g_intTrackNo)) then
  1170. '                    ParseParameters = false
  1171. '                    exit function
  1172. '                end if
  1173.         
  1174.                 i = i + 1
  1175.  
  1176.             case "-year"                        
  1177.                 ' Get the year of the output file.
  1178.                 g_strYear = ReadString( args, i, i+1 )
  1179. '                if g_strYear = "" then
  1180. '                    ParseParameters = false
  1181. '                    exit function
  1182. '                end if
  1183.         
  1184.                 i = i + 1
  1185.  
  1186.  
  1187.  
  1188.             case "-genre"                        
  1189.                 ' Get the genre of the output file.
  1190.                 g_strGenre = ReadString( args, i, i+1 )
  1191. '                if g_strGenre = "" then
  1192. '                    ParseParameters = false
  1193. '                    exit function
  1194. '                end if
  1195.  
  1196.                 i = i + 1
  1197.  
  1198.             case "-copyright"                        
  1199.                 ' Get the copyright information of the output file.
  1200.                 g_strCopyright = ReadString( args, i, i+1 )
  1201. '                if g_strCopyright = "" then
  1202. '                    ParseParameters = false
  1203. '                    exit function
  1204. '                end if
  1205.         
  1206.                 i = i + 1
  1207.  
  1208.             case "-description"
  1209.                 ' Get the descrption of the output file.
  1210.                 g_strDescription = ReadString( args, i, i+1 )
  1211. '                if g_strDescription = "" then
  1212. '                    ParseParameters = false
  1213. '                    exit function
  1214. '                end if
  1215.         
  1216.                 i = i + 1
  1217.  
  1218.             case "-rating"                        
  1219.                 ' Get the rating of the output file.
  1220.                 g_strRating = ReadString( args, i, i+1 )
  1221. '                if g_strRating = "" then
  1222. '                    ParseParameters = false
  1223. '                    exit function
  1224. '                end if
  1225.         
  1226.                 i = i + 1
  1227.  
  1228.             case "-saveprofile"                            
  1229.                 ' Get the profile file name to be saved.
  1230.                 g_strProfileSave = ReadString( args, i, i+1 )
  1231.                 if g_strProfileSave = "" then
  1232.                     ParseParameters = false
  1233.                     exit function
  1234.                 end if
  1235.         
  1236.                 i = i + 1
  1237.         
  1238.             case "-loadprofile"                            
  1239.                 ' Get the profile file name to be loaded.
  1240.                 g_strProfileLoad = ReadString( args, i, i+1 )
  1241.                 if g_strProfileLoad = "" then
  1242.                     ParseParameters = false
  1243.                     exit function
  1244.                 end if
  1245.         
  1246.                 i = i + 1
  1247.  
  1248.             case "-verbose"
  1249.                 ' Get the verbose mode.
  1250.                 g_intVerbose = ReadInteger( args, i, i+1 )
  1251.                 if g_intVerbose = -1 then
  1252.                     ParseParameters = false
  1253.                     exit function
  1254.                 end if
  1255.  
  1256.                 i = i + 1
  1257.  
  1258.             case "-s_config"
  1259.                 ' Save the WEU configuration file
  1260.                 strSaveToCfgFile = ReadString( args, i, i+1 )
  1261.                 if strSaveToCfgFile = "" then
  1262.                     ParseParameters = false
  1263.                     exit function
  1264.                 end if
  1265.  
  1266.                 i = i + 1
  1267.             case "-config"
  1268.                 if strLoadFromCfgFile = "" then
  1269.                     ParseParameters = false
  1270.                     exit function
  1271.                 end if
  1272.         
  1273.                 i = i + 1
  1274.  
  1275.             case "-maxpacket"
  1276.                 g_intMaxPacketSize = ReadInteger( args, i, i+1 )
  1277.                 if g_intMaxPacketSize = -1 then
  1278.                     ParseParameters = false
  1279.                     exit function
  1280.                 end if
  1281.  
  1282.                 i = i + 1
  1283.  
  1284.             case "-minpacket"
  1285.                 g_intMinPacketSize = ReadInteger( args, i, i+1 )
  1286.                 if g_intMinPacketSize = -1 then
  1287.                     ParseParameters = false
  1288.                     exit function
  1289.                 end if
  1290.         
  1291.                 i = i + 1
  1292.  
  1293.             case else
  1294.                 ' Show an error information for unrecognized parameter.
  1295.                 OutputInfo "Invalid parameter: " & args(i)
  1296.                 ParseParameters = false
  1297.                 exit function
  1298.         end select
  1299.     
  1300.     next
  1301.  
  1302.     if strSaveToCfgFile <> "" then
  1303.         strSaveToCfgFile = g_objFileSystem.GetAbsolutePathName( strSaveToCfgFile )
  1304.  
  1305.         ' Add extension if necessary
  1306.         if Right( LCase( strSaveToCfgFile ), 4 ) <>  ".weu" then
  1307.             strSaveToCfgFile = strSaveToCfgFile & ".weu"
  1308.         end if
  1309.  
  1310.         CreateOutputFolder( g_objFileSystem.GetParentFolderName( strSaveToCfgFile ) )    
  1311.         set objTextFile = g_objFileSystem.OpenTextFile( strSaveToCfgFile, 2, True )
  1312.         objTextFile.Write( strArguments )
  1313.         objTextFile.close
  1314.     end if
  1315.  
  1316.     ParseParameters = true
  1317. end function
  1318.  
  1319. ' Show help information of this program.
  1320. function ShowHelp()
  1321.     OutputInfo "Encode from files or devices to Windows Media files or streams. Supported"
  1322.     OutputInfo "source file formats are .wmv, .wma, .asf, .avi., .wav. .mpg, .mp3, .bmp,"
  1323.     OutputInfo "and .jpg."
  1324.     OutputInfo ""
  1325.     OutputInfo ""
  1326.     OutputInfo "Usage for I/O and statistics."
  1327.     OutputInfo ""
  1328.     OutputInfo "[-wme] <Windows Media Encoder session file>"
  1329.     OutputInfo "    Loads an existing Windows Media Encoder session file."
  1330.     OutputInfo "[-input] <file or directory name>"
  1331.     OutputInfo "    The file or directory to be encoded."
  1332.     OutputInfo "    Specify a file or directory name. If you specify a directory, supported"
  1333.     OutputInfo "    files in the directory will be encoded to the output directory, using"
  1334.     OutputInfo "    the same encoding settings. "
  1335.     OutputInfo "    Enclose file and directory names that have spaces in quotations."
  1336.     OutputInfo "    For example: -input ""c:\my sample.wmv"""
  1337.     OutputInfo "[-adevice] <audio device number>"
  1338.     OutputInfo "    The audio capture device to encode from."
  1339.     OutputInfo "    Use -devices to list all available capture devices."  
  1340.     OutputInfo "    When encoding from devices, you must specify a duration using -duration."      
  1341.     OutputInfo "[-vdevice] <video device number>"
  1342.     OutputInfo "    The video capture device to encode from."
  1343.     OutputInfo "    Use -devices to list all available capture devices."  
  1344.     OutputInfo "    When capturing from devices, you must specify a duration using -duration."      
  1345.     OutputInfo "[-output] <file or directory name>"
  1346.     OutputInfo "    The name of the output file or directory."
  1347.     OutputInfo "    If the input is a file, -output corresponds to a file name. If the input"
  1348.     OutputInfo "    is a directory, -output corresponds to a directory name."
  1349.     OutputInfo "    The output directory will be created if it doesn't already exist."
  1350.     OutputInfo "    An extension is automatically appended to output files."
  1351.     OutputInfo "    (.wma for audio-only Windows Media files, and .wmv for video-only or"
  1352.     OutputInfo "    audio and video Windows Media files.)"
  1353.     OutputInfo "[-outputstring] <string>"
  1354.     OutputInfo "    The string to be attached to every output file name for directory mode."
  1355.     OutputInfo "[-broadcast] <port>"
  1356.     OutputInfo "    Broadcasts via HTTP on the port specified. The default port is 8080."
  1357.     OutputInfo "[-time] <start time> <end time>"
  1358.     OutputInfo "    Specify the time segment (in msec) to be encoded. Use 'end' for"
  1359.     OutputInfo "    <end time> if you want to encode to the end of the file."
  1360.     OutputInfo "[-silent]"
  1361.     OutputInfo "    Prevents statistics from being displayed after encoding is finished."
  1362.     OutputInfo "[-config] <input configuration file>"
  1363.     OutputInfo "    Inputs arguments from a configuration file. The default extension is .weu."
  1364.     OutputInfo "    Parameters in the file can be overridden by later arguments."
  1365.     OutputInfo "[-s_config] <output configuration file>"
  1366.     OutputInfo "    Creates a configuration file. The file name extension .weu is appended"
  1367.     OutputInfo "    automatically."
  1368.     OutputInfo ""
  1369.     OutputInfo ""
  1370.     OutputInfo "Usage for profiles."
  1371.     OutputInfo "    You can override parameters in a profile by appending arguments to a"
  1372.     OutputInfo "    command."
  1373.     OutputInfo ""
  1374.     OutputInfo "[-profile] <profile code>"
  1375.     OutputInfo "    Specifies a predefined profile to use in the session."
  1376.     OutputInfo ""
  1377.     OutputInfo "Codes and basic descriptions for the predefined profiles:"
  1378.     OutputInfo "Audio/Video:"
  1379.     OutputInfo "    av20: Profile_AudioVideo_Modem_28K (actual rate: 20Kbps)"
  1380.     OutputInfo "    av32: Profile_AudioVideo_Modem_56K (32 Kbps)"
  1381.     OutputInfo "    av100: Profile_AudioVideo_LAN_100K (100 Kbps)"
  1382.     OutputInfo "    av225: Profile_AudioVideo_LAN_256K (225 Kbps)"
  1383.     OutputInfo "    av350: Profile_AudioVideo_LANDSL_384K (350 Kbps)"
  1384.     OutputInfo "    av450: Profile_AudioVideo_LANDSL_768K (450 Kbps)"
  1385.     OutputInfo "    av700: Profile_AudioVideo_NearBroadcast_700K (700 Kbps)"
  1386.     OutputInfo "    av1400: Profile_AudioVideo_NearBroadcast_1400K (1400 Kbps)"
  1387.     OutputInfo "    av350pal: Profile_AudioVideo_Broadband_PAL_384K (350 Kbps)"
  1388.     OutputInfo "    av700pal: Profile_AudioVideo_NearBroadcast_PAL_700K (700 Kbps)"
  1389.     OutputInfo "    av100_2p: Profile_AudioVideo_LAN_100K_2Pass (100 Kbps)"
  1390.     OutputInfo "    av350_2p: Profile_AudioVideo_LANDSL_384K_2Pass (350 Kbps)"
  1391.     OutputInfo "    av600vbr: Profile_AudioVideo_FilmVBR_600K (600 Kbps)"
  1392.     OutputInfo "    avq97vbr: Profile_AudioVideo_FilmVBR_Quality97 (Quality 97)"
  1393.     OutputInfo ""
  1394.     OutputInfo "Audio-only:"
  1395.     OutputInfo "    a20_1: Profile_AudioOnly_FMRadioMono_28K (20 Kbps)"
  1396.     OutputInfo "    a20_2: Profile_AudioOnly_FMRadioStereo_28K (20 Kbps)"
  1397.     OutputInfo "    a32: Profile_AudioOnly_Modem_56K (32 Kbps)"
  1398.     OutputInfo "    a48: Profile_AudioOnly_NearCDQuality_48K (48 Kbps)"
  1399.     OutputInfo "    a64: Profile_AudioOnly_CDQuality_64K (64 Kbps)"
  1400.     OutputInfo "    a96: Profile_AudioOnly_CDAudiophileQuality_96K (96 Kbps)"
  1401.     OutputInfo "    a128: Profile_AudioOnly_CDAudiophileQuality_128K (128 Kbps)"
  1402.     OutputInfo ""
  1403.     OutputInfo "Video-only:"
  1404.     OutputInfo "    v20: Profile_VideoOnly_Modem_28K (20 Kbps)"
  1405.     OutputInfo "    v32: Profile_VideoOnly_Modem_56K (32 Kbps)"
  1406.     OutputInfo ""
  1407.     OutputInfo "[-loadprofile] <profile file name>"
  1408.     OutputInfo "    Specifies a Windows Media Encoder or custom profile to use."
  1409.     OutputInfo ""
  1410.     OutputInfo ""
  1411.     OutputInfo "Usage for audio settings."
  1412.     OutputInfo ""
  1413.     OutputInfo "[-a_codec] <codec index>"
  1414.     OutputInfo "    Audio codec to be used. Use -a_codecs to list available codecs."
  1415.     OutputInfo "    Specify codec index:"
  1416.     OutputInfo "    WMA9STD: Windows Media Audio 9 (default)."
  1417.     OutputInfo "    WMA9PRO: Windows Media Audio 9 Professional"
  1418.     OutputInfo "    WMSP9:   Windows Media Audio 9 Voice"
  1419.     OutputInfo "    WMA9LSL:  Windows Media Audio 9 Lossless; -a_mode 2 required"
  1420.     OutputInfo "    PCM: No compression"
  1421.     OutputInfo "[-a_codecs]"
  1422.     OutputInfo "    Lists all audio codecs."
  1423.     OutputInfo "[-a_content] <mode>"
  1424.     OutputInfo "    Audio content mode for the Windows Media Audio v9 Voice codec."
  1425.     OutputInfo "    0 = No special mode for the audio content (default)"
  1426.     OutputInfo "    1 = Speech mode"
  1427.     OutputInfo "    2 = Mixed (speech and music) mode (also requires -a_contentedl)"
  1428.     OutputInfo "    You must also specify the Windows Media Audio v9 Voice codec."
  1429.     OutputInfo "[-a_contentedl] <file name>"
  1430.     OutputInfo "    Specifies the places in audio content where music starts and ends. To do"
  1431.     OutputInfo "    this, you must first create an optimization definition file. You"
  1432.     OutputInfo "    must specify the Windows Media Audio Voice codec and -a_content 2 when"
  1433.     OutputInfo "    when you use the -a_contentedl option."
  1434.     OutputInfo "[-a_folddown6to2] <surround mix> <center mix> <LFE>"
  1435.     OutputInfo "    Fold-down coefficients for multichannel audio. Use whole numbers only."
  1436.     OutputInfo "    Values will be converted to negative numbers. Valid numbers are 0 to 144."
  1437.     OutputInfo "    For example, -a_folddown6to2 10 3 3"
  1438.     OutputInfo "[-a_formats]"
  1439.     OutputInfo "    Lists all audio formats for each codec."
  1440.     OutputInfo "[-a_mode] <mode_number>"
  1441.     OutputInfo "    Audio encoding to be used."
  1442.     OutputInfo "    0: 1-pass CBR (default)."
  1443.     OutputInfo "    1: 2-pass CBR."
  1444.     OutputInfo "    2: Quality-based VBR."
  1445.     OutputInfo "    3: Bit rate-based VBR (two-pass)."
  1446.     OutputInfo "    4: Bit rate-based peak VBR (two-pass)." 
  1447.     OutputInfo "[-a_peakbitrate] <peak bit rate>"
  1448.     OutputInfo "    Specifies the peak bit rate in bits per second for peak bit rate-based"
  1449.     OutputInfo "    VBR for audio. If not specified, the peak bit rate is 1.5 times the"
  1450.     OutputInfo "    audio bit rate."
  1451.     OutputInfo "[-a_peakbuffer] <peak buffer>"
  1452.     OutputInfo "    Buffer in msec for audio with peak bit rate-based VBR. If not specified,"
  1453.     OutputInfo "    the default of 3000 msec is used."
  1454.     OutputInfo "[-a_setting] <setting>"
  1455.     OutputInfo "    Specifies the formats for audio setting."
  1456.     OutputInfo "    Use -a_formats to list supported audio formats for each codec."
  1457.     OutputInfo ""
  1458.     OutputInfo "    -a_setting Bitrate_SamplingRate_Channels. For example, -a_setting 48_44_2"
  1459.     OutputInfo "    specifies 48 Kbps, 44 kHz, and two channels. The default is 64_44_2."
  1460.     OutputInfo ""
  1461.     OutputInfo "    If you use quality-based VBR: -a_setting Qxx_SamplingRate_Channels."
  1462.     OutputInfo "    For example, -a_setting Q90_44_2 specifies a quality level of 90, 44 kHz,"
  1463.     OutputInfo "    and 2 channels."
  1464.     OutputInfo ""
  1465.     OutputInfo "    If you use the Windows Media Audio Professional 9:" 
  1466.     OutputInfo "    -a_setting Bitrate_SamplingRate_Channels_BitDepth."
  1467.     OutputInfo "    For example, -a_setting 250_44_2_24 specifies 250 Kbps, 44 kHz, "
  1468.     OutputInfo "    two channels, and 24-bit encoding. Use either 16- or 24-bit encoding."
  1469.     OutputInfo "    24-bit is the default."
  1470.     OutputInfo ""
  1471.     OutputInfo "    If you use the Windows Media Audio 9 Lossless codec:"
  1472.     OutputInfo "    -a_setting Qxx_SamplingRate_Channels_BitDepth. For example,"
  1473.     OutputInfo "    -a_setting Q100_44_2_24 specifies VBR Quality 100, 44 kHz, two channel,"
  1474.     OutputInfo "    24-bit encoding. (Quality-based VBR and a quality level of 100 is"
  1475.     OutputInfo "    required with this codec.)"
  1476.     OutputInfo "[-audioonly]"
  1477.     OutputInfo "    Encodes the audio portion of the stream only."
  1478.     OutputInfo ""
  1479.     OutputInfo ""
  1480.     OutputInfo ""
  1481.     OutputInfo ""
  1482.     OutputInfo "Usage for video settings."
  1483.     OutputInfo ""
  1484.     OutputInfo "[-v_codec] <codec index>"
  1485.     OutputInfo "    Video codec to be used. Use -v_codecs to list available video codecs."
  1486.     OutputInfo "    Specify codec index:"
  1487.     OutputInfo "       WMV7: Windows Media Video 7."
  1488.     OutputInfo "       WMV8: Windows Media Video 8.1."
  1489.     OutputInfo "       WMV9: Windows Media Video 9 (default)."
  1490.     OutputInfo "       WMS9: Windows Media Video Screen 9."
  1491.     OutputInfo "       MP41: ISO MPEG-4 Video v1"
  1492.     OutputInfo "       UNCOMP: Full frames (uncompressed)"
  1493.     OutputInfo "[-v_width] <width>"
  1494.     OutputInfo "    Video frame width in pixels to be encoded. Default: Source video width."
  1495.     OutputInfo "[-v_height] <height>"
  1496.     OutputInfo "    Video frame height in pixels to be encoded. Default: Source video height."
  1497.     OutputInfo "[-v_framerate] <rate>"
  1498.     OutputInfo "    Video frame rate in floating point to be encoded. Default: 30 fps."
  1499.     OutputInfo "[-v_keydist] <time>"
  1500.     OutputInfo "    Key frame distance in seconds for video. Default: 10 seconds."
  1501.     OutputInfo "[-v_preproc] <filter number>"
  1502.     OutputInfo "    Video preprocessing for certain input sources."
  1503.     OutputInfo "    0: None (for progressive video input)."
  1504.     OutputInfo "    1: Deinterlace but preserve the size."
  1505.     OutputInfo "       For example, 640x480x30 interlace to 640x480x30 progressive."
  1506.     OutputInfo "    2: Deinterlace but halve the size."
  1507.     OutputInfo "       For example, 640x480x30 interlace to 320x240x30 progressive."
  1508.     OutputInfo "    3: Deinterlace, halve the size, and double the frame rate."
  1509.     OutputInfo "       For example, 640x480x30 interlace to 320x240x60 progressive."
  1510.     OutputInfo "    4: Deinterlace, halve vertical size, and double frame rate."
  1511.     OutputInfo "       For example, 320x480x30 interlace to 320x240x60 progressive."
  1512.     OutputInfo "    5: Inverse telecine from 30fps to 24fps."
  1513.     OutputInfo "    6: Inverse telecine - First field is top field with AA telecine pattern."
  1514.     OutputInfo "    7: Inverse telecine - First field is top field with BB telecine pattern."
  1515.     OutputInfo "    8: Inverse telecine - First field is top field with BC telecine pattern."
  1516.     OutputInfo "    9: Inverse telecine - First field is top field with CD telecine pattern."
  1517.     OutputInfo "    10:Inverse telecine - First field is top field with DD telecine pattern."
  1518.     OutputInfo "    11:Inverse telecine - First field is bottom field with AA telecine "
  1519.     OutputInfo "       pattern."
  1520.     OutputInfo "    12:Inverse telecine - First field is bottom field with BB telecine"
  1521.     OutputInfo "       pattern."
  1522.     OutputInfo "    13:Inverse telecine - First field is bottom field with BC telecine"
  1523.     OutputInfo "       pattern."
  1524.     OutputInfo "    14:Inverse telecine - First field is bottom field with CD telecine"
  1525.     OutputInfo "      pattern."
  1526.     OutputInfo "    15:Inverse telecine - First field is bottom field with DD telecine"
  1527.     OutputInfo "       pattern."
  1528.     OutputInfo "    16:Interlaced encoding."
  1529.     OutputInfo "    17:Interlaced encoding - First field is top field."
  1530.     OutputInfo "    18:Interlaced encoding - First field is bottom field."
  1531.     OutputInfo "    Default: 0: None."
  1532.     OutputInfo "[-v_clip] <left> <top> <right> <bottom>"
  1533.     OutputInfo "    The region of the image (with respect to source) to be clipped/encoded."
  1534.     OutputInfo "    If the right is 0 or greater than width, it is ignored and re-assigned"
  1535.     OutputInfo "    to width. If the bottom is 0 or greater than height, it is ignored and"
  1536.     OutputInfo "    re-assigned to height."
  1537.     OutputInfo "[-v_mode] <mode number>"
  1538.     OutputInfo "    Video encoding to be used."
  1539.     OutputInfo "    0: 1-pass CBR (default)."
  1540.     OutputInfo "    1: 2-pass CBR."
  1541.     OutputInfo "    2: Quality-based VBR."
  1542.     OutputInfo "    3: Bit rate-based VBR (two-pass)."
  1543.     OutputInfo "    4: Peak bit rate-based VBR (two-pass)."
  1544.     OutputInfo "[-v_bitrate] <bit rate>"
  1545.     OutputInfo "    Video bit rate in bits per second to be encoded. Default: 250000 bps."
  1546.     OutputInfo "    Set this to 0 for audio-only coding."
  1547.     OutputInfo "[-v_buffer] <buffer>"
  1548.     OutputInfo "    Delay buffer in milliseconds for video. Default: 5000 msec."
  1549.     OutputInfo "[-v_quality] <quality>"
  1550.     OutputInfo "    CBR: Quality/smoothness tradeoff. 0 to 100, 0 being the smoothest."
  1551.     OutputInfo "    Default: 75."
  1552.     OutputInfo "    Quality-based VBR: Image quality for the video. Encode video to the"
  1553.     OutputInfo "    specified quality, regardless of bit rate. Default: 95"
  1554.     OutputInfo "[-v_peakbitrate] <peak bit rate>"
  1555.     OutputInfo "    Peak bit rate in bits per second for peak bit rate-based VBR for video."
  1556.     OutputInfo "    If not specified, the peak bit rate is 1.5 times the video bit rate."
  1557.     OutputInfo "[-v_peakbuffer] <peak buffer>"
  1558.     OutputInfo "    Buffer in msec for video, with peak bit rate-based VBR. If not specified,"
  1559.     OutputInfo "    the default of 5000 msec is used."
  1560.     OutputInfo "[-v_performance] <performance>"
  1561.     OutputInfo "    Use to adjust hardware performance settings. Possible values: 0, 20, 40,"
  1562.     OutputInfo "    60, 80, and 100, with 100 representing the highest quality. If you do not"
  1563.     OutputInfo "    specify a value, codec defaults are used."
  1564.     OutputInfo "[-v_profile] <device conformance>"
  1565.     OutputInfo "    Specifies the category of complexity of the encoded content. Use if you"
  1566.     OutputInfo "    are targeting your content for playback on a hardware device other than"
  1567.     OutputInfo "    a computer. Some hardware devices only support certain categories. (Refer"
  1568.     OutputInfo "    to the documentation for your device for more information.) If you do not"
  1569.     OutputInfo "    add the -v_profile option to a command, the correct complexity setting is"
  1570.     OutputInfo "    selected automatically during encoding. Possible values are SP (Simple),"
  1571.     OutputInfo "    MP (main), or CP (complex)."
  1572.     OutputInfo "[-duration] <seconds>"
  1573.     OutputInfo "    Amount of time in seconds to encode. Use when sourcing from devices."
  1574.     OutputInfo "[-saveprofile] <file name>"
  1575.     OutputInfo "    Saves current settings to a file for later reuse. Default file name"
  1576.     OutputInfo "    extension is .prx."
  1577.     OutputInfo "[-devices]"
  1578.     OutputInfo "    Lists audio and video capture devices."
  1579.     OutputInfo "[-v_codecs]"
  1580.     OutputInfo "    Lists all video codecs."
  1581.     OutputInfo "[-videoonly]"
  1582.     OutputInfo "    Encodes video stream only."
  1583.     OutputInfo "[-pixelratio] <x y>"
  1584.     OutputInfo "    Specifies the video pixel aspect ratio."
  1585.     OutputInfo "[-pixelformat] <format>"
  1586.     OutputInfo "    Specifies the video pixel format. Possible values:"
  1587.     OutputInfo "    I420"
  1588.     OutputInfo "    IYUV"
  1589.     OutputInfo "    RGB24"
  1590.     OutputInfo "    RGB32"
  1591.     OutputInfo "    RGB555"
  1592.     OutputInfo "    RGB565"
  1593.     OutputInfo "    RGB8"
  1594.     OutputInfo "    UYVY"
  1595.     OutputInfo "    YUY2"
  1596.     OutputInfo "    YV12"
  1597.     OutputInfo "    YVU9"
  1598.     OutputInfo "    YVYU"
  1599.     OutputInfo "[-maxpacket] <packet size>"
  1600.     OutputInfo "    Specifies the maximum packet size in bytes."
  1601.     OutputInfo "[-minpacket] <packet size>"
  1602.     OutputInfo "    Specifies the minimum packet size in bytes."
  1603.     OutputInfo ""
  1604.     OutputInfo "[-title] <string>"
  1605.     OutputInfo "    Title of the content. Enclose strings with spaces in quotations. For"
  1606.     OutputInfo "    example: -title ""Windows Media Sample"""
  1607.     OutputInfo "[-author] <string>"
  1608.     Outputinfo "[-album] <string>"
  1609.     Outputinfo "[-year] <string>"
  1610.     Outputinfo "[-trackno] <string>"
  1611.     Outputinfo "[-genre] <string>"
  1612.     OutputInfo "[-copyright] <string>"
  1613.     OutputInfo "[-description] <string>    "
  1614.     OutputInfo "[-rating] <string>"
  1615.         OutputInfo "NOTE: The maximum string length for each one is 255. It is recommended"
  1616.     OutputInfo "      that you enclose all string parameters in quotations.    "
  1617.  
  1618. end function
  1619.  
  1620. ' Brings up the encoder utility chm file
  1621. function ShowHelpChm()
  1622.     dim strChmFileName, strExeName, strCommandLine
  1623.     dim RetVal
  1624.     dim objShell, objDir
  1625.  
  1626.     'Create a shell object. we will use this to execute the command
  1627.     Set objShell = WScript.CreateObject("WScript.Shell")
  1628.  
  1629.     'Get the Windows directory object
  1630.     set objDir = g_objFileSystem.GetSpecialFolder( 0 )
  1631.  
  1632.     'make the executable name ( %windir%\hh.exe ) form the windows dir object
  1633.     strExeName = objDir.drive & "\" & objDir.name & "\"
  1634.     strExeName = strExeName & "hh.exe" 
  1635.  
  1636.     'make the full path name for the chm file to be shown
  1637.     strChmFileName = """" & ObjDir.drive & "\program files\windows media components\encoder\wmencutil.chm" & """"
  1638.  
  1639.     'make the command line
  1640.     strCommandLine = strExeName & " " & strChmFileName
  1641.  
  1642.     'run the command and dont wait for the app to finish
  1643.     RetVal = objShell.Run( strCommandLine, 4, FALSE )
  1644. end function
  1645.  
  1646. ' Print out info about the input file
  1647. function PrintFileInfo()
  1648.     dim objFileInfo
  1649.     dim strFileInfo
  1650.     dim strInput2
  1651.         
  1652.     strInput2 = g_objFileSystem.GetAbsolutePathName( g_strInput )
  1653.  
  1654.     set objFileInfo = WScript.CreateObject( "FileInfo.MediaInfo" )
  1655.  
  1656.     objFileInfo.FileName = strInput2
  1657.  
  1658.     strFileInfo = objFileInfo.MediaInfo
  1659.  
  1660.     OutputInfo strFileInfo
  1661. end function
  1662.  
  1663. ' List audio codecs.
  1664. function ListAudioCodecs()
  1665.     dim objProfile
  1666.     dim objName
  1667.     dim intFourCC
  1668.     dim intVBRMode
  1669.     dim strCodecId
  1670.     dim intCount
  1671.     
  1672.     set objProfile = WScript.CreateObject( "WMENCEng.WMEncProfile2" )
  1673.  
  1674.     OutputInfo vbCrLf & "Audio Codecs: "
  1675.  
  1676.     ' For all VBR modes    
  1677.     for intVBRMode = 1 to 4
  1678.         objProfile.VBRMode(WMENC_AUDIO, 0) = intVBRMode
  1679.  
  1680.         select case intVBRMode
  1681.             case WMENC_PVM_NONE
  1682.                 OutputInfo "CBR Mode :"
  1683.  
  1684.             case WMENC_PVM_PEAK
  1685.                 OutputInfo "Peak Bit Rate-Based VBR Audio Mode :"
  1686.  
  1687.             case WMENC_PVM_UNCONSTRAINED
  1688.                 OutputInfo "Quality-Based VBR Audio Mode :"
  1689.  
  1690.             case WMENC_PVM_BITRATE_BASED
  1691.                 OutputInfo "Bit Rate-Based VBR Audio Mode :"
  1692.     
  1693.             case else
  1694.                 OutputInfo "Unknown Mode"
  1695.         end select
  1696.  
  1697.         intCount = 0
  1698.         ' Enum all audio codecs
  1699.         for i=0 to objProfile.AudioCodecCount-1
  1700.             objProfile.EnumAudioCodec i, objName
  1701.  
  1702.             'Check and display fourcc
  1703.             intFourCC = objProfile.GetCodecFourCCFromIndex(WMENC_AUDIO, i)
  1704.             select case intFourCC
  1705.                 case WMA9STD_FOURCC
  1706.                     strCodecId = WMA9STD
  1707.  
  1708.                 case WMA9PRO_FOURCC
  1709.                     strCodecId = WMA9PRO
  1710.  
  1711.                 case WMA9LSL_FOURCC
  1712.                     strCodecId = WMA9LSL
  1713.  
  1714.                 case WMSPEECH_FOURCC
  1715.                     strCodecId = WMSPEECH
  1716.  
  1717.                 case PCM_FOURCC
  1718.                     strCodecId = PCM
  1719.  
  1720.                 case else
  1721.                     strCodecId = ""
  1722.             end select
  1723.  
  1724.             if( strCodecId <> "" ) then  
  1725.                 OutputInfo vbTab &  "[" & intCount & "] "  & strCodecId & " : " & objName
  1726.                 intCount = intCount + 1
  1727.             end if
  1728.         next
  1729.  
  1730.         OutputInfo vbCrLf
  1731.     next
  1732.     
  1733. end function
  1734.  
  1735. ' List video codecs.
  1736. function ListVideoCodecs()
  1737.     dim objProfile
  1738.     dim objName
  1739.     dim intFourCC
  1740.     dim intVBRMode
  1741.     dim strCodecId
  1742.     dim intCount
  1743.     
  1744.     set objProfile = WScript.CreateObject( "WMENCEng.WMEncProfile2" )
  1745.  
  1746.     OutputInfo vbCrLf & "Video Codecs: "
  1747.  
  1748.     ' For all VBR modes    
  1749.     for intVBRMode = 1 to 4
  1750.         objProfile.VBRMode(WMENC_VIDEO, 0) = intVBRMode
  1751.  
  1752.         select case intVBRMode
  1753.             case WMENC_PVM_NONE
  1754.                 OutputInfo "CBR Mode :"
  1755.  
  1756.             case WMENC_PVM_PEAK
  1757.                 OutputInfo "Peak Bit Rate-Based VBR Audio Mode :"
  1758.  
  1759.             case WMENC_PVM_UNCONSTRAINED
  1760.                 OutputInfo "Quality-Based VBR Audio Mode :"
  1761.  
  1762.             case WMENC_PVM_BITRATE_BASED
  1763.                 OutputInfo "Bit Rate-Based VBR Audio Mode :"
  1764.     
  1765.             case else
  1766.                 OutputInfo "Unknown Mode"
  1767.         end select
  1768.  
  1769.         intCount = 0
  1770.         ' Enum all video codecs
  1771.         for i=0 to objProfile.VideoCodecCount-1
  1772.             objProfile.EnumVideoCodec i, objName
  1773.  
  1774.             'Check and display fourcc
  1775.             intFourCC = objProfile.GetCodecFourCCFromIndex(WMENC_VIDEO, i)
  1776.             select case intFourCC
  1777.                 case WMV7_FOURCC
  1778.                     strCodecId = WMV7
  1779.  
  1780.                 case WMV8_FOURCC
  1781.                     strCodecId = WMV8
  1782.  
  1783.                 case WMV9_FOURCC
  1784.                     strCodecId = WMV9
  1785.  
  1786.                 case WMS9_FOURCC
  1787.                     strCodecId = WMS9
  1788.  
  1789.                 case MP41_FOURCC
  1790.                     strCodecId = MP41
  1791.  
  1792.                 case UNCOMP_FOURCC
  1793.                     strCodecId = UNCOMP
  1794.  
  1795.                 case else
  1796.                     strCodecId = ""
  1797.             end select
  1798.  
  1799.             if( strCodecId <> "" ) then  
  1800.                 OutputInfo vbTab &  "[" & i & "] "  & strCodecId & " : " & objName
  1801.                 intCount = intCount + 1
  1802.             end if
  1803.         next
  1804.         OutputInfo vbCrLf
  1805.     next
  1806.  
  1807.  
  1808. end function
  1809.  
  1810. ' List audio formats.
  1811. function ListAudioFormats()
  1812.     dim objProfile
  1813.     dim objName
  1814.     dim intFourCC
  1815.     dim intVBRMode
  1816.     dim strCodecId, strAudFormatName, strSetting
  1817.     dim intAudioSampleRate, intAudioChannels, intAudioBitsPerSample, intAudioBitrate 
  1818.     dim intArgSpaceCount, intBitrateSpaceCount, intSamplingRateSpaceCount, intChannelSpaceCount
  1819.     
  1820.     intArgSpaceCount = 24
  1821.     intBitrateSpaceCount = 16
  1822.     intSamplingRateSpaceCount = 20
  1823.     intChannelSpaceCount = 10
  1824.  
  1825.     set objProfile = WScript.CreateObject( "WMENCEng.WMEncProfile2" )
  1826.  
  1827.     OutputInfo vbCrLf & "Audio Codecs: "
  1828.  
  1829.     ' For all VBR modes    
  1830.     for intVBRMode = 1 to 4
  1831.         objProfile.VBRMode(WMENC_AUDIO, 0) = intVBRMode
  1832.  
  1833.         select case intVBRMode
  1834.             case WMENC_PVM_NONE
  1835.                 OutputInfo "CBR Mode :"
  1836.  
  1837.             case WMENC_PVM_PEAK
  1838.                 OutputInfo "Peak Bit Rate-Based VBR Audio Mode :"
  1839.  
  1840.             case WMENC_PVM_UNCONSTRAINED
  1841.                 OutputInfo "Quality-Based VBR Audio Mode :"
  1842.  
  1843.             case WMENC_PVM_BITRATE_BASED
  1844.                 OutputInfo "Bit Rate-Based VBR Audio Mode :"
  1845.     
  1846.             case else
  1847.                 OutputInfo "Unknown Mode"
  1848.         end select
  1849.  
  1850.         ' Enum all audio codecs
  1851.         for i=0 to objProfile.AudioCodecCount-1
  1852.             objProfile.EnumAudioCodec i, objName
  1853.  
  1854.             'Check and display fourcc
  1855.             intFourCC = objProfile.GetCodecFourCCFromIndex(WMENC_AUDIO, i)
  1856.             select case intFourCC
  1857.                 case WMA9STD_FOURCC
  1858.                     strCodecId = WMA9STD
  1859.  
  1860.                 case WMA9PRO_FOURCC
  1861.                     strCodecId = WMA9PRO
  1862.  
  1863.                 case WMA9LSL_FOURCC
  1864.                     strCodecId = WMA9LSL
  1865.  
  1866.                 case WMSPEECH_FOURCC
  1867.                     strCodecId = WMSPEECH
  1868.  
  1869.                 case PCM_FOURCC
  1870.                     strCodecId = PCM
  1871.             end select
  1872.  
  1873.             if( strCodecId <> "" ) then  
  1874.                 OutputInfo vbTab & strCodecId & " : " & objName & " (" & strCodecId & "):"
  1875.             else
  1876.                 OutputInfo vbTab & objName & ":"
  1877.             end if
  1878.  
  1879.             OutputInfo vbCrLf
  1880.  
  1881.             if intVBRMode = WMENC_PVM_UNCONSTRAINED then
  1882.                 if strCodecId <> WMA9PRO then
  1883.                     OutputInfo vbTab & vbTab & PadSpaces("Argument", intArgSpaceCount) & PadSpaces("Quality", intBitrateSpaceCount) & PadSpaces("Sampling rate", intSamplingRateSpaceCount) & "Channel"
  1884.                 else
  1885.                     OutputInfo vbTab & vbTab & PadSpaces("Argument", intArgSpaceCount) & PadSpaces("Quality", intBitrateSpaceCount) & PadSpaces("Sampling rate", intSamplingRateSpaceCount) & PadSpaces("Channel", intChannelSpaceCount) & "BitsPerSample"
  1886.                 end if
  1887.             else
  1888.                 if strCodecId <> WMA9PRO and strCodecId <> WMA9LSL then
  1889.                     OutputInfo vbTab & vbTab & PadSpaces("Argument", intArgSpaceCount) & PadSpaces("Bitrate", intBitrateSpaceCount) & PadSpaces("Sampling rate", intSamplingRateSpaceCount) & "Channel"
  1890.                 else
  1891.                     OutputInfo vbTab & vbTab & PadSpaces("Argument", intArgSpaceCount) & PadSpaces("Bitrate", intBitrateSpaceCount) & PadSpaces("Sampling rate", intSamplingRateSpaceCount) & PadSpaces("Channel", intChannelSpaceCount) & "BitsPerSample"
  1892.                 end if
  1893.             end if
  1894.  
  1895.             OutputInfo vbTab & vbTab & "------------------------------------------------------------------------------------"
  1896.  
  1897.             For j=0 To objProfile.audioFormatCount(i) - 1
  1898.                 intAudioBitrate = objProfile.EnumAudioFormat(i, j, strAudFormatName, intAudioSampleRate, intAudioChannels, intAudioBitsPerSample)
  1899.  
  1900.                 if intVBRMode <> WMENC_PVM_UNCONSTRAINED then
  1901.                     intAudioBitrate = CLng(intAudioBitrate / 1000)
  1902.                 else
  1903.                     intAudioBitrate = "Q" & intAudioBitrate
  1904.                 end if
  1905.  
  1906.                 if intAudioSampleRate = 88200 then
  1907.                     intAudioSampleRate = 88
  1908.                 elseif intAudioSampleRate = 44100 then
  1909.                     intAudioSampleRate = 44
  1910.                 elseif intAudioSampleRate = 22050 then
  1911.                     intAudioSampleRate = 22
  1912.                 elseif intAudioSampleRate = 11025 then
  1913.                     intAudioSampleRate = 11
  1914.                 else
  1915.                     intAudioSampleRate = Clng(intAudioSampleRate / 1000)
  1916.                 end if
  1917.  
  1918.                 if strCodecId <> WMA9PRO and strCodecId <> WMA9LSL then
  1919.                     strSetting = intAudioBitrate & "_" & intAudioSampleRate & "_" & intAudioChannels
  1920.                     OutputInfo vbTab & vbTab & PadSpaces(strSetting, intArgSpaceCount) & PadSpaces(intAudioBitrate, intBitrateSpaceCount) & PadSpaces(intAudioSampleRate, intSamplingRateSpaceCount) & intAudioChannels
  1921.                 else 
  1922.                     strSetting = intAudioBitrate & "_" & intAudioSampleRate & "_" & intAudioChannels & "_" & intAudioBitsPerSample
  1923.                     OutputInfo vbTab & vbTab & PadSpaces(strSetting, intArgSpaceCount) & PadSpaces(intAudioBitrate, intBitrateSpaceCount) & PadSpaces(intAudioSampleRate, intSamplingRateSpaceCount) & PadSpaces(intAudioChannels, intChannelSpaceCount) & intAudioBitsPerSample
  1924.                 end if
  1925.  
  1926.             next 
  1927.     
  1928.             OutputInfo vbCrLf & vbCrLf
  1929.  
  1930.         next
  1931.         OutputInfo vbCrLf
  1932.     next
  1933.     
  1934. end function
  1935.  
  1936.  
  1937. ' Add spaces to the end of arg to create intCount characters string
  1938. function PadSpaces( arg, intCount )
  1939.  
  1940.     if Len(arg) >= intCount then
  1941.         PadSpaces = arg
  1942.         exit function
  1943.     end if
  1944.  
  1945.     PadSpaces = arg & Space( intCount - Len(arg) )
  1946. end function
  1947.  
  1948.  
  1949.  
  1950. ' List all audio and video devices.
  1951. function ListDevices()
  1952.     dim objManager, objPlugin, i, j, k, count
  1953.  
  1954.     set objManager = g_objEncoder.SourcePluginInfoManager
  1955.  
  1956.     for i=0 to 1
  1957.         if i = 0 then
  1958.             OutputInfo "audio device:"
  1959.         elseif i = 1 then
  1960.             OutputInfo "video device:"
  1961.         end if
  1962.         count = 0
  1963.         for j=0 to objManager.Count-1
  1964.             set objPlugin = objManager.Item(j)
  1965.  
  1966.             if objPlugin.Resources = true then
  1967.                 if i = 0 then
  1968.                     if objPlugin.MediaType = 1 or objPlugin.MediaType = 3 then
  1969.                         ' Enum all devices in this type
  1970.                         for k=0 to objPlugin.Count-1
  1971.                             OutputInfo vbTab & count & " : " & objPlugin.Item(k)
  1972.                             count = count + 1
  1973.                         next
  1974.                     end if
  1975.                 elseif i = 1 then
  1976.                     if objPlugin.MediaType = 2 or objPlugin.MediaType = 3 or objPlugin.MediaType = 6 then
  1977.                         ' Enum all devices in this type
  1978.                         for k=0 to objPlugin.Count-1
  1979.                             OutputInfo vbTab & count & " : " & objPlugin.Item(k)
  1980.                             count = count + 1
  1981.                         next
  1982.                     end if
  1983.                 end if
  1984.             end if
  1985.         next
  1986.     next
  1987. end function
  1988.  
  1989.  
  1990. ' Setup encoder using the current settings.
  1991. function SetupEncoder( )
  1992.     
  1993.     if not CreateSourceGroup() then
  1994.         SetupEncoder = false
  1995.         exit function
  1996.     end if
  1997.  
  1998.     if not SetupInput() then
  1999.         SetupEncoder = false
  2000.         exit function
  2001.     end if
  2002.  
  2003.     if not SetupProfile() then
  2004.         SetupEncoder = false
  2005.         exit function
  2006.     end if
  2007.  
  2008.     if not SetupOutput()  then
  2009.         SetupEncoder = false
  2010.         exit function
  2011.     end if
  2012.  
  2013.     if not SetupTime() then
  2014.         SetupEncoder = false
  2015.         exit function
  2016.     end if
  2017.  
  2018.     if not SetupDisplayInfo() then
  2019.         SetupEncoder = false
  2020.         exit function
  2021.     end if
  2022.  
  2023.     g_objEncoder.AutoStop = true
  2024.  
  2025.     SetupEncoder = true
  2026. end function
  2027.  
  2028. ' Create Source group by loading from wme or adding a new one
  2029. function CreateSourceGroup()
  2030.  
  2031.     dim objProfile
  2032.     dim intCodecIndex
  2033.  
  2034.     ' If a WME file is provided, load the encoding configuration from this WME file.
  2035.     if g_strWMEFile <> "" then
  2036.         on error resume next
  2037.  
  2038.         ' Load enocder session from a WME file
  2039.         g_objEncoder.Load( g_objFileSystem.GetAbsolutePathName( g_strWMEFile ) )
  2040.  
  2041.         ' Add a new source group.
  2042.         set g_objSourceGroup = g_objEncoder.SourceGroupCollection.Item(0)
  2043.  
  2044.         set objProfile = g_objSourceGroup.Profile
  2045.         set g_objProfile = WScript.CreateObject( "WMENCENG.WMEncProfile2" )
  2046.         g_objProfile.LoadFromIWMProfile( objProfile )
  2047.  
  2048.         ' If source file has an auido stream, get the audio source.
  2049.         if g_objSourceGroup.SourceCount( WMENC_AUDIO ) > 0 then
  2050.             set g_objAudioSource = g_objSourceGroup.Source( WMENC_AUDIO, 0 )
  2051.             intCodecIndex = g_objProfile.Audience(0).AudioCodec( 0 )
  2052.             g_objProfile.EnumAudioCodec intCodecIndex, g_strAudioCodecName
  2053.         end if
  2054.  
  2055.         ' If source file has a video stream, get the video source.
  2056.         if g_objSourceGroup.SourceCount( WMENC_VIDEO ) > 0 then
  2057.             set g_objVideoSource = g_objSourceGroup.Source( WMENC_VIDEO, 0 )
  2058.             intCodecIndex = g_objProfile.Audience(0).VideoCodec( 0 )
  2059.             g_objProfile.EnumVideoCodec intCodecIndex, g_strVideoCodecName
  2060.         end if
  2061.  
  2062.         g_blnCreateCustomProfile = false
  2063.  
  2064.         if g_intMaxPacketSize = -1 then
  2065.             g_intMaxPacketSize = objProfile.MaxPacketSize
  2066.         end if
  2067.  
  2068.         if err.number <> 0 then
  2069.             OutputInfo "Loading the session (.wme) file failed: " & g_strWMEFile
  2070.             err.Clear
  2071.             CreateSourceGroup = false
  2072.             exit function
  2073.         end if
  2074.     else
  2075.         ' Create a new source group for this session
  2076.         set g_objSourceGroup = g_objEncoder.SourceGroupCollection.Add( "SG_1" )
  2077.     end if
  2078.  
  2079.     CreateSourceGroup = true
  2080. end function
  2081.  
  2082. ' Setup profile configuration
  2083. function SetupProfile()
  2084.     on error resume next
  2085.  
  2086.     dim objProfile
  2087.     dim objAudience
  2088.     dim blnRet
  2089.     dim strProfileLoad
  2090.     dim objFileInfo
  2091.     dim intVideoFramerateTemp
  2092.     dim intSourceVideoFramerate
  2093.     dim strInput2
  2094.  
  2095.     ' save the global frame rate, since we might over-write it based on the input files frame rate
  2096.     intVideoFramerateTemp = g_intVideoFramerate
  2097.  
  2098.     if IsNull(g_objProfile) then
  2099.         Set g_objProfile = WScript.CreateObject( "WMENCEng.WMEncProfile2" )
  2100.         g_objProfile.ContentType = g_intSessionType
  2101.         g_objProfile.ProfileName = "WMCMDProfile"
  2102.  
  2103.         Set objAudience = g_objProfile.AddAudience( 10000000 )
  2104.     else
  2105.         g_objProfile.ContentType = g_intSessionType
  2106.         Set objAudience = g_objProfile.Audience( 0 )
  2107.  
  2108.     end if
  2109.  
  2110.  
  2111.     if g_intVideoFramerate = -1 then
  2112.         ' Assume 30 fps unless we can get the input files framerate
  2113.         g_intVideoFramerate = 30000
  2114.     end if
  2115.  
  2116.     strInput2 = g_objFileSystem.GetAbsolutePathName( g_strInput )
  2117.     set objFileInfo = WScript.CreateObject( "FileInfo.MediaInfo" )
  2118.     objFileInfo.FileName = strInput2
  2119.     intSourceVideoFramerate = 100000
  2120.     intSourceVideoFramerate = objFileInfo.FrameRate * 1000
  2121.     if intSourceVideoFramerate = 0 then
  2122.         intSourceVideoFramerate = 100000
  2123.     end if
  2124.  
  2125.     ' Set the video frame rate to lower of the source input or user specified frame rate for better quality
  2126.     if intSourceVideoFramerate < g_intVideoFramerate then
  2127.         g_intVideoFramerate = intSourceVideoFramerate
  2128.     end if
  2129.  
  2130.     ' if profile string is specified load it
  2131.     if g_strProfile <> "" then
  2132.         blnRet = SetupPredefinedProfile( objAudience )
  2133.  
  2134.         g_blnCreateCustomProfile = false
  2135.  
  2136.         if not blnRet then
  2137.             SetupProfile = false
  2138.             exit function
  2139.         end if
  2140.     end if
  2141.  
  2142.     if g_strProfileLoad <> "" then
  2143.         strProfileLoad = g_objFileSystem.GetAbsolutePathName( g_strProfileLoad )
  2144.         g_objProfile.LoadFromFile strProfileLoad
  2145.         g_blnCreateCustomProfile = false
  2146.         Set objAudience = g_objProfile.Audience( 0 )
  2147.  
  2148.         ' enable two pass if required
  2149.         if not isnull( g_objVideoSource ) then                
  2150.             if g_objProfile.VBRMode( WMENC_VIDEO, 0 ) = WMENC_PVM_PEAK or g_objProfile.VBRMode( WMENC_VIDEO, 0 ) = WMENC_PVM_BITRATE_BASED then
  2151.                 g_objVideoSource.PreProcessPass = 1
  2152.             end if
  2153.             
  2154.             if objAudience.VideoFPS(0) > g_intVideoFramerate then
  2155.                 objAudience.VideoFPS(0) = g_intVideoFramerate
  2156.             else
  2157.                 g_intVideoFramerate = objAudience.VideoFPS(0)
  2158.             end if
  2159.         end if
  2160.  
  2161.         if not isnull( g_objAudioSource ) then                
  2162.             if g_objProfile.VBRMode( WMENC_AUDIO, 0 ) = WMENC_PVM_PEAK or g_objProfile.VBRMode( WMENC_AUDIO, 0 ) = WMENC_PVM_BITRATE_BASED then
  2163.                 g_objAudioSource.PreProcessPass = 1
  2164.             end if
  2165.         end if
  2166.     end if
  2167.  
  2168.     ' First time: override the WME or predefined profile with custom values
  2169.     blnRet = SetupCustomProfile( objAudience )
  2170.     if not blnRet then
  2171.         SetupProfile = false
  2172.         exit function
  2173.     end if
  2174.  
  2175.     if g_blnCreateCustomProfile then
  2176.         ' Second time: Update profile based on input specified and default values
  2177.         LoadProfileDefaults()
  2178.  
  2179.         blnRet = SetupCustomProfile( objAudience )
  2180.         if not blnRet then
  2181.             SetupProfile = false
  2182.             exit function
  2183.         end if
  2184.     end if
  2185.  
  2186.     ' Set a few more things like interlaced coding and pixel ratio
  2187.     if g_intPixelAspectRatioX <> -1 or g_intPixelAspectRatioY <> -1 then
  2188.         g_objProfile.NonSquarePixelMode(0) = true
  2189.     end if
  2190.  
  2191.     if g_intVideoPreprocess >= 16 and g_intVideoPreprocess <= 18 then
  2192.         g_objProfile.InterlaceMode(0) = true
  2193.     end if
  2194.  
  2195.     if g_intMinPacketSize <> -1 then
  2196.         g_objProfile.MinPacketSize = g_intMinPacketSize
  2197.     end if
  2198.  
  2199.     ' Set the profile in encoder.
  2200.     g_objSourceGroup.Profile = g_objProfile
  2201.  
  2202.     if g_intMaxPacketSize <> -1 then
  2203.         g_objSourceGroup.Profile.MaxPacketSize = g_intMaxPacketSize
  2204.     end if
  2205.  
  2206.     g_intVideoFramerate = intVideoFramerateTemp
  2207.  
  2208.     ' Invalid profile
  2209.     if err.number <> 0 then
  2210.         OutputInfo "Invalid profile: 0x" & Hex( err.number ) & " " & err.Description
  2211.         err.Clear
  2212.         SetupProfile = false
  2213.         exit function
  2214.     end if
  2215.  
  2216.     if g_strProfileSave <> "" then
  2217.         g_objProfile.SaveToFile g_strProfileSave
  2218.     end if
  2219.  
  2220.     SetupProfile = true
  2221. end function
  2222.  
  2223. ' Setup ouptut configuration.
  2224. function SetupOutput()
  2225.     ' Is an output file name provided?
  2226.     if g_strOutput <> "" then
  2227.         ' Is this output name a directory?
  2228.         if g_objFileSystem.FolderExists( g_strOutput ) then
  2229.             
  2230.             ' If the output name is a directory, create the real output file name.
  2231.             ' If the input is a file, use the file name of the input file (extension is not ussed).
  2232.             ' If the inputs are devices, use 'output' as the output name.            
  2233.             if g_strInput <> "" then
  2234.                 g_strOutput = g_strOutput & "\\" & g_objFileSystem.GetBaseName( g_strInput )
  2235.             else
  2236.                 g_strOutput = g_strOutput & "\\output"
  2237.             end if
  2238.         end if
  2239.  
  2240.         ' If the output file name doesn't have a extension, create a proper one.
  2241.         if g_objFileSystem.GetExtensionName( g_strOutput ) = "" then            
  2242.  
  2243.             ' Does "." already exist in the output file name.
  2244.             ' If not, append "." to the output file name.
  2245.             if Right( g_strOutput, 1 ) <>  "." then
  2246.                 g_strOutput = g_strOutput & "."
  2247.             end if
  2248.  
  2249.             ' Does this session have a video source?
  2250.             ' If it has video stream, append wmv extension, otherwise wma extension is appended.
  2251.             if g_objSourceGroup.SourceCount( WMENC_VIDEO ) > 0 then
  2252.                 g_strOutput = g_strOutput & "wmv"
  2253.             else
  2254.                 g_strOutput = g_strOutput & "wma"
  2255.             end if
  2256.         end if
  2257.  
  2258.         CreateOutputFolder( g_objFileSystem.GetParentFolderName( g_objFileSystem.GetAbsolutePathName( g_strOutput ) ) )
  2259.  
  2260.         g_objEncoder.File.LocalFileName = g_strOutput
  2261.     else
  2262.         ' Get the output file name from WME file.
  2263.         if not IsNull(g_objEncoder.File.LocalFileName) then
  2264.             g_strOutput = g_objEncoder.File.LocalFileName
  2265.         end if
  2266.     end if
  2267.  
  2268.     ' Enable HTTP broadcasting for the encoder if a broadcast port is provided.
  2269.     if g_intBroadcast <> -1 then
  2270.         g_objEncoder.Broadcast.PortNumber( WMENC_PROTOCOL_HTTP ) = g_intBroadcast
  2271.     end if
  2272.  
  2273.     ' Enable push if push server is specified
  2274.     if g_strPushServer <> "" then
  2275.         g_objEncoder.Broadcast.ServerName = g_strPushServer
  2276.         g_objEncoder.Broadcast.PublishingPoint = g_strPublishingPoint
  2277.         if g_strPushTemplate <> "" then
  2278.             g_objEncoder.Broadcast.Template = g_strPushTemplate
  2279.         end if
  2280.     end if
  2281.  
  2282.     SetupOutput = true
  2283. end function
  2284.  
  2285. ' Setup display configuration
  2286. function SetupDisplayInfo()
  2287.     dim objDisplayInfo
  2288.     dim objAttributes
  2289.     
  2290.     set objDisplayInfo = g_objEncoder.DisplayInfo
  2291.     set objAttributes = g_objEncoder.Attributes
  2292.  
  2293.     ' Is title set?
  2294.     if g_strTitle <> "" then
  2295.         objDisplayInfo.Title = g_strTitle
  2296.     end if
  2297.  
  2298.     ' Is author set?
  2299.     if g_strAuthor <> "" then
  2300.         objDisplayInfo.Author = g_strAuthor
  2301.         objAttributes.Add "WM/AlbumArtist", CStr(g_strAuthor)
  2302.     end if
  2303.  
  2304.     ' Is album set?
  2305.     if g_strAlbum <> "" then
  2306.         objAttributes.Add "WM/AlbumTitle", CStr(g_strAlbum)        
  2307.     end if
  2308.  
  2309.     ' Is genre set?
  2310.     if g_strGenre <> "" then
  2311.         objAttributes.Add "WM/Genre", CStr(g_strGenre)
  2312.     end if
  2313.  
  2314.     ' Is track number set?
  2315.     if (g_intTrackNo <> "") and (IsNumeric(g_intTrackNo)) then
  2316.         objAttributes.Add "WM/TrackNumber", CInt(g_intTrackNo)
  2317.         objAttributes.Add "WM/Track", (CInt(g_intTrackNo)-1)
  2318.     else g_intTrackNo = ""
  2319.     end if
  2320.  
  2321.     ' Is year set?
  2322.     if (g_strYear <> "") and (IsNumeric(g_strYear)) then
  2323.         objAttributes.Add "WM/Year", CStr(g_strYear)
  2324.     else g_strYear = ""
  2325.     end if
  2326.  
  2327.  
  2328.     ' Is copyright set?
  2329.     if g_strCopyright <> "" then
  2330.         objDisplayInfo.Copyright = g_strCopyright
  2331.     end if
  2332.  
  2333.     ' Is description set?
  2334.     if g_strDescription <> "" then
  2335.         objDisplayInfo.Description = g_strDescription
  2336.     end if
  2337.  
  2338.     ' Is rating set?
  2339.     if g_strRating <> "" then
  2340.         objDisplayInfo.Rating = g_strRating
  2341.     end if
  2342.  
  2343.     ' Add folddown coefficients
  2344.     if g_intAudioSurroundMix <> -1 then
  2345.         objAttributes.Add "SurroundMix", -g_intAudioSurroundMix
  2346.         objAttributes.Add "CenterMix", -g_intAudioCenterMix
  2347.         objAttributes.Add "LFEMix", -g_intAudioLEFMix
  2348.     end if
  2349.  
  2350.     SetupDisplayInfo = true
  2351. end function
  2352.  
  2353. ' Setup a new profile based on predefined profiles
  2354. function SetupPredefinedProfile(objAudience)
  2355.     dim intAudioCodecIndex, intVideoCodecIndex
  2356.     
  2357.     '  The following defined built in profiles.  Built in profiles are defined by the following:
  2358.     '  Audio:  Codec, channels, sample rate, bit rate, bit depth
  2359.     '  Video:  Codec, bit rate, width, height, fpsx1000, buffer (ms), smoothness, key frame 
  2360.     '  New built in profiles can be added by creating a new case statement and specifying
  2361.     '  audio and video profile settings.
  2362.     select case LCase( g_strProfile )
  2363.         case "av20":
  2364.             SetupAudioAudience objAudience, "WMA9STD", 1, 8000, 5000, 16
  2365.             SetupVideoAudience objAudience, "WMV9", 15000, 160, 120, 15000, 5000, 75, 10000
  2366.  
  2367.         case "av32":
  2368.             SetupAudioAudience objAudience, "WMA9STD", 1, 11025, 10168, 16
  2369.             SetupVideoAudience objAudience, "WMV9", 22000, 176, 144, 15000, 5000, 75, 10000
  2370.  
  2371.         case "av100":
  2372.             SetupAudioAudience objAudience, "WMA9STD", 1, 16000, 16000, 16
  2373.             SetupVideoAudience objAudience, "WMV9", 84000, 320, 240, 15000, 5000, 75, 10000
  2374.  
  2375.         case "av225":
  2376.             SetupAudioAudience objAudience, "WMA9STD", 2, 32000, 40000, 16
  2377.             SetupVideoAudience objAudience, "WMV9", 185000, 320, 240, 30000, 5000, 75, 10000
  2378.  
  2379.         case "av350":
  2380.             SetupAudioAudience objAudience, "WMA9STD", 2, 32000, 48000, 16
  2381.             SetupVideoAudience objAudience, "WMV9", 302000, 320, 240, 30000, 5000, 75, 10000
  2382.  
  2383.         case "av450":
  2384.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 64040, 16
  2385.             SetupVideoAudience objAudience, "WMV9", 386000, 320, 240, 30000, 5000, 75, 10000
  2386.  
  2387.         case "av700":
  2388.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 64040, 16
  2389.             SetupVideoAudience objAudience, "WMV9", 636000, 320, 240, 30000, 5000, 75, 10000
  2390.  
  2391.         case "av1400":
  2392.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 128040, 16
  2393.             SetupVideoAudience objAudience, "WMV9", 1272000, 320, 240, 30000, 5000, 75, 10000
  2394.  
  2395.         case "av350pal":
  2396.             SetupAudioAudience objAudience, "WMA9STD", 2, 32000, 48000, 16
  2397.             SetupVideoAudience objAudience, "WMV9", 302000, 384, 288, 25000, 5000, 75, 10000
  2398.  
  2399.         case "av700pal":
  2400.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 64040, 16
  2401.             SetupVideoAudience objAudience, "WMV9", 636000, 384, 288, 25000, 5000, 75, 10000
  2402.  
  2403.         case "av100_2p":
  2404.             SetupAudioAudience objAudience, "WMA9STD", 1, 16000, 16000, 16
  2405.             SetupVideoAudience objAudience, "WMV9", 84000, 320, 240, 15000, 5000, 75, 10000
  2406.             g_objAudioSource.PreProcessPass = 1
  2407.             g_objVideoSource.PreProcessPass = 1
  2408.  
  2409.         case "av350_2p"
  2410.             SetupAudioAudience objAudience, "WMA9STD", 2, 32000, 48000, 16
  2411.             SetupVideoAudience objAudience, "WMV9", 302000, 320, 240, 30000, 5000, 75, 10000
  2412.             g_objAudioSource.PreProcessPass = 1
  2413.             g_objVideoSource.PreProcessPass = 1
  2414.  
  2415.         case "av600vbr":
  2416.             g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_PEAK
  2417.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 64040, 16
  2418.             SetupVideoAudience objAudience, "WMV9", 536000, 320, 240, 24000, 5000, 75, 10000
  2419.             
  2420.             objAudience.VideoPeakBitrate(0) = 1.5 * objAudience.VideoBitrate(0)
  2421.             objAudience.VideoBufferMax(0) = 5000
  2422.  
  2423.             ' Turn telecine and two pass video on
  2424.             g_objVideoSource.Optimization = WMENC_VIDEO_INVERSETELECINE
  2425.             g_objVideoSource.PreProcessPass = 1    
  2426.  
  2427.         case "avq97vbr":
  2428.             g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_UNCONSTRAINED
  2429.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 64040, 16
  2430.             SetupVideoAudience objAudience, "WMV9", 536000, 320, 240, 24000, 5000, 97, 10000
  2431.  
  2432.             ' Turn telecine on
  2433.             g_objVideoSource.Optimization = WMENC_VIDEO_INVERSETELECINE
  2434.  
  2435.         case "a20_1":
  2436.             SetupAudioAudience objAudience, "WMA9STD", 1, 22050, 20008, 16
  2437.  
  2438.         case "a20_2":
  2439.             SetupAudioAudience objAudience, "WMA9STD", 2, 22050, 20008, 16
  2440.  
  2441.         case "a32":
  2442.             SetupAudioAudience objAudience, "WMA9STD", 2, 32000, 32000, 16
  2443.  
  2444.         case "a48":
  2445.             SetupAudioAudience objAudience, "WMA9STD", 2, 32000, 48024, 16
  2446.  
  2447.         case "a64":
  2448.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 64016, 16
  2449.  
  2450.         case "a96":
  2451.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 96024, 16
  2452.  
  2453.         case "a128":
  2454.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 128016, 16
  2455.  
  2456.         case "v20":
  2457.             SetupVideoAudience objAudience, "WMV9", 20000, 176, 144, 15000, 5000, 75, 10000
  2458.  
  2459.         case "v32":
  2460.             SetupVideoAudience objAudience, "WMV9", 32000, 240, 176, 15000, 5000, 75, 10000
  2461.  
  2462.         case else
  2463.             OutputInfo "No predefined profile found."
  2464.             SetupPredefinedProfile = false
  2465.             exit function
  2466.  
  2467.     end select
  2468.  
  2469.     SetupPredefinedProfile = true
  2470. end function
  2471.  
  2472. ' Given audio parameters this will setup the audience
  2473. function SetupAudioAudience(objAudience, strAudioCodec, intChannels, intSampleRate, intBitrate, intBitsPerSample)
  2474.     dim intAudioCodecIndex
  2475.  
  2476.     intAudioCodecIndex = GetAudioCodecIndex(strAudioCodec)
  2477.     g_objProfile.EnumAudioCodec intAudioCodecIndex, g_strAudioCodecName
  2478.     
  2479.     objAudience.AudioCodec(0) = intAudioCodecIndex
  2480.     objAudience.SetAudioConfig 0, intChannels, intSampleRate, intBitrate, intBitsPerSample
  2481. end function
  2482.  
  2483. ' Given video parameters this will setup the audience
  2484. function SetupVideoAudience(objAudience, strVideoCodec, intBitrate, intWidth, intHeight, intFps, intBufferWindow, intSmoothness, intKeyFrame)
  2485.     dim intVideoCodecIndex
  2486.     
  2487.     if intFps > g_intVideoFramerate then
  2488.         intFps = g_intVideoFramerate
  2489.     else
  2490.         g_intVideoFramerate = intFps
  2491.     end if
  2492.  
  2493.     intVideoCodecIndex = GetVideoCodecIndex(strVideoCodec)
  2494.     g_objProfile.EnumVideoCodec intVideoCodecIndex, g_strVideoCodecName
  2495.  
  2496.     objAudience.VideoCodec(0) = intVideoCodecIndex
  2497.     objAudience.VideoBitrate(0) = intBitrate
  2498.     objAudience.VideoWidth(0) = intWidth
  2499.     objAudience.VideoHeight(0) = intHeight
  2500.     objAudience.VideoFps(0) = intFps
  2501.     objAudience.VideoKeyFrameDistance(0) = intKeyFrame
  2502.     objAudience.VideoBufferSize(0) = intBufferWindow
  2503.  
  2504.     ' For quality vbr mode use intSmoothness as VBR quality
  2505.     if g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_UNCONSTRAINED then
  2506.         objAudience.VideoCompressionQuality(0) = intSmoothness
  2507.     else
  2508.         objAudience.VideoImageSharpness(0) = intSmoothness
  2509.     end if
  2510. end function
  2511.  
  2512. ' Given audio string(eg WMA9STD) this returns the audio codec index
  2513. function GetAudioCodecIndex(strAudioCodec)
  2514.     dim intFourCC
  2515.  
  2516.     select case strAudioCodec
  2517.         case WMA9STD
  2518.             intFourCC = WMA9STD_FOURCC
  2519.  
  2520.         case WMA9PRO
  2521.             intFourCC = WMA9PRO_FOURCC
  2522.  
  2523.         case WMA9LSL
  2524.             intFourCC = WMA9LSL_FOURCC
  2525.  
  2526.         case WMSPEECH
  2527.             intFourCC = WMSPEECH_FOURCC
  2528.  
  2529.         case PCM
  2530.             intFourCC = PCM_FOURCC
  2531.  
  2532.         case else
  2533.             intFourCC = WMA9STD_FOURCC
  2534.     end select
  2535.  
  2536.     GetAudioCodecIndex = g_objProfile.GetCodecIndexFromFourCC(WMENC_AUDIO, intFourCC)
  2537.  
  2538. end function
  2539.  
  2540. ' Given the video string(eg WMV9) this returns the video codec index
  2541. function GetVideoCodecIndex(strVideoCodec)
  2542.     dim intFourCC
  2543.  
  2544.     select case strVideoCodec
  2545.         case WMV7
  2546.             intFourCC = WMV7_FOURCC
  2547.  
  2548.         case WMV8
  2549.             intFourCC = WMV8_FOURCC
  2550.  
  2551.         case WMV9
  2552.             intFourCC = WMV9_FOURCC
  2553.  
  2554.         case WMS9
  2555.             intFourCC = WMS9_FOURCC
  2556.  
  2557.         case MP41
  2558.             intFourCC = MP41_FOURCC
  2559.  
  2560.         case UNCOMP
  2561.             intFourCC = UNCOMP_FOURCC
  2562.  
  2563.         case else
  2564.             intFourCC = WMV9_FOURCC
  2565.     end select
  2566.     
  2567.     GetVideoCodecIndex = g_objProfile.GetCodecIndexFromFourCC(WMENC_VIDEO, intFourCC)
  2568.  
  2569. end function
  2570.  
  2571. ' Setup a new profile based on predefined profiles
  2572. function SetupCustomProfile(objAudience)
  2573.     dim intAudioCodecIndex, intVideoCodecIndex
  2574.     dim blnRet
  2575.  
  2576.     if not g_blnAudioOnly and not g_blnVideoOnly  then
  2577.         if g_strVideoCodec = UNCOMP and g_strAudioCodec <> PCM then
  2578.             OutputInfo "Audio codec must be uncompressed when using uncompressed video codec"
  2579.             SetupCustomProfile = false
  2580.             exit function
  2581.         end if
  2582.  
  2583.         if g_strVideoCodec <> UNCOMP and g_strAudioCodec = PCM then
  2584.             OutputInfo "Video codec must be uncompressed when using uncompressed audio codec"
  2585.             SetupCustomProfile = false
  2586.             exit function
  2587.         end if    
  2588.     end if
  2589.  
  2590.     if not isnull( g_objAudioSource ) then
  2591.         blnRet = SetupCustomAudioProfile( objAudience )
  2592.         if not blnRet then
  2593.             SetupCustomProfile = false
  2594.             exit function
  2595.         end if
  2596.     end if
  2597.  
  2598.     if not isnull( g_objVideoSource ) then
  2599.         blnRet = SetupCustomVideoProfile( objAudience )
  2600.         if not blnRet then
  2601.             SetupCustomProfile = false
  2602.             exit function
  2603.         end if
  2604.     end if
  2605.  
  2606.     SetupCustomProfile = true
  2607.  
  2608. end function
  2609.  
  2610. ' Setup the audio part of the custom profile
  2611. function SetupCustomAudioProfile(objAudience)
  2612.     on error resume next
  2613.  
  2614.     ' Setup audio
  2615.     dim intAudioCodecIndex, intAudioBitrate, intAudioSampleRate, intAudioChannels, intBitDepth, intFourCC
  2616.     dim strTemp
  2617.     dim intNextArgStart, intNextArgEnd
  2618.     dim blnAudioQuality, blnValidBitrate, blnValidSampleRate, blnValidChannels, blnValidBitDepth
  2619.  
  2620.  
  2621.     'Set audio vbr mode
  2622.     if g_intAudioVBRMode <> -1 then
  2623.         select case g_intAudioVBRMode
  2624.             case 0 ' 1 pass CBR
  2625.  
  2626.             case 1 ' 2 pass CBR
  2627.                 g_objAudioSource.PreProcessPass = 1
  2628.  
  2629.             case 2 ' Quality VBR mode
  2630.                 g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_UNCONSTRAINED
  2631.  
  2632.             case 3 ' 2 pass bitrate based VBR
  2633.                 g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_BITRATE_BASED
  2634.                 g_objAudioSource.PreProcessPass = 1
  2635.  
  2636.             case 4 ' 2 pass bitrate-based peak constrained VBR
  2637.                 g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_PEAK
  2638.                 g_objAudioSource.PreProcessPass = 1
  2639.  
  2640.             case else
  2641.                 OutputInfo "Invalid -a_mode <mode_number>"
  2642.                 SetupCustomAudioProfile = false
  2643.                 exit function
  2644.         end select
  2645.     end if
  2646.  
  2647.  
  2648.     ' Set audio codec
  2649.     if g_strAudioCodec <> "" then
  2650.         intAudioCodecIndex = GetAudioCodecIndex(g_strAudioCodec)
  2651.         intFourCC = g_objProfile.EnumAudioCodec(intAudioCodecIndex, g_strAudioCodecName)
  2652.  
  2653.         objAudience.AudioCodec(0) = intAudioCodecIndex
  2654.     end if
  2655.  
  2656.     'Parse the a_setting string to extract audio bitrate sample rate and stuff like that
  2657.     if g_strAudioSetting <> "" then
  2658.         intNextArgStart = instr(g_strAudioSetting, "_")
  2659.         strTemp = left(g_strAudioSetting, intNextArgStart-1)
  2660.     
  2661.         if ucase( left(strTemp, 1) ) = "Q" then
  2662.             g_intAudioVBRMode = 2
  2663.             g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_UNCONSTRAINED
  2664.  
  2665.             blnAudioQuality = true
  2666.             intAudioBitrate = ConvertStringToInteger( mid(strTemp, 2 ) )
  2667.         else
  2668.             intAudioBitrate = ConvertStringToInteger( strTemp )
  2669.         end if
  2670.  
  2671.         'OutputInfo "****Audio bit rate is " & intAudioBitrate
  2672.  
  2673.         intNextArgEnd = instr(intNextArgStart+1, g_strAudioSetting, "_")
  2674.         strTemp = mid(g_strAudioSetting, intNextArgStart+1, intNextArgEnd-intNextArgStart-1)
  2675.         intAudioSampleRate = ConvertStringToInteger( strTemp )
  2676.         'OutputInfo "****Audio sample rate is " & intAudioSampleRate
  2677.     
  2678.         intNextArgStart = intNextArgEnd
  2679.         intNextArgEnd = instr(intNextArgStart+1, g_strAudioSetting, "_")
  2680.         if intNextArgEnd > 0 then
  2681.             strTemp = mid(g_strAudioSetting, intNextArgStart+1, intNextArgEnd-intNextArgStart-1)
  2682.         else
  2683.             strTemp = mid(g_strAudioSetting, intNextArgStart+1)
  2684.         end if
  2685.         intAudioChannels = ConvertStringToInteger( strTemp )
  2686.         'OutputInfo "****Audio channels are " & intAudioChannels
  2687.  
  2688.         if intNextArgEnd > 0 then
  2689.             strTemp = mid(g_strAudioSetting, intNextArgEnd+1)
  2690.             intBitDepth = ConvertStringToInteger( strTemp )
  2691.         else
  2692.             intBitDepth = 16
  2693.         end if
  2694.         'OutputInfo "****Audio bit depth is " & intBitDepth
  2695.  
  2696.         if intAudioBitrate = -1 or intAudioSampleRate = -1 or intAudioChannels = -1 or intBitDepth = -1 then
  2697.             SetupCustomAudioProfile = false
  2698.             err.Raise &H80070057
  2699.             exit function
  2700.         end if
  2701.  
  2702.         'Convert bitrate and samplerate to actual values
  2703.         if blnAudioQuality = false then
  2704.             if intAudioBitrate = 1411 then
  2705.                 intAudioBitrate = 1411200
  2706.             elseif intAudioBitrate = 705 then
  2707.                 intAudioBitrate = 705600
  2708.             elseif intAudioBitrate = 353 then
  2709.                 intAudioBitrate = 352800
  2710.             else
  2711.                 intAudioBitrate = 1000 * intAudioBitrate
  2712.             end if
  2713.         end if
  2714.  
  2715.         ' For peak vbr mode set peakbitrate and peak buffer
  2716.         if g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_PEAK then
  2717.             if g_intAudioPeakBuffer <> -1 then
  2718.                 objAudience.AudioBufferMax(0) = g_intAudioPeakBuffer
  2719.             end if
  2720.  
  2721.             if g_intAudioPeakBitrate = -1 then
  2722.                 objAudience.AudioPeakBitrate(0) = 1.5 * intAudioBitrate
  2723.             else
  2724.                 objAudience.AudioPeakBitrate(0) = g_intAudioPeakBitrate
  2725.             end if
  2726.             'OutputInfo "****Audio peak bit rate is " & objAudience.AudioPeakbitrate(0)
  2727.             'OutputInfo "****Audio peak buffer is " & objAudience.AudioBufferMax(0)
  2728.         end if
  2729.  
  2730.         if intAudioSampleRate = 88 then
  2731.             intAudioSampleRate = 88200
  2732.         elseif intAudioSampleRate = 44 then
  2733.             intAudioSampleRate = 44100
  2734.         elseif intAudioSampleRate = 22 then
  2735.             intAudioSampleRate = 22050
  2736.         elseif intAudioSampleRate = 11 then
  2737.             intAudioSampleRate = 11025
  2738.         else
  2739.             intAudioSampleRate = 1000 * intAudioSampleRate
  2740.         end if
  2741.  
  2742.         ' Validate values for bitrate, samplerate, channels and depth 
  2743.         if blnAudioQuality = false then
  2744.             blnValidBitrate = CheckForValidAudioBitRates( intAudioBitrate )
  2745.             if blnValidBitrate = false then 
  2746.                 OutputInfo "Invalid audio bit rate " & intAudioBitrate
  2747.                 SetupCustomAudioProfile = false
  2748.                 exit function
  2749.             end if
  2750.         end if
  2751.  
  2752.         blnValidSampleRate = CheckForValidAudioSamplingRates( intAudioSampleRate )
  2753.         if blnValidSampleRate = false then 
  2754.             OutputInfo "Invalid audio sample rate " & intAudioSampleRate
  2755.             SetupCustomAudioProfile = false
  2756.             exit function
  2757.         end if
  2758.  
  2759.         blnValidChannels = CheckForValidAudioChannel( intAudioChannels )
  2760.         if blnValidChannels = false then 
  2761.             OutputInfo "Invalid audio channels " & intAudioChannels
  2762.             SetupCustomAudioProfile = false
  2763.             exit function
  2764.         end if
  2765.  
  2766.         blnValidBitDepth = CheckForValidDepth( intBitDepth )
  2767.         if blnValidBitDepth = false then 
  2768.             OutputInfo "Invalid bits per sample " & intBitDepth
  2769.             SetupCustomAudioProfile = false
  2770.             exit function
  2771.         end if
  2772.  
  2773.         objAudience.SetAudioConfig 0, intAudioChannels, intAudioSampleRate, intAudioBitrate, intBitDepth
  2774.     end if
  2775.  
  2776.     SetupCustomAudioProfile = true
  2777.  
  2778. end function
  2779.  
  2780. ' Setup the video part of the custom profile
  2781. function SetupCustomVideoProfile(objAudience)
  2782.     on error resume next
  2783.  
  2784.     ' Setup audio
  2785.     dim intVideoCodecIndex, intFourCC
  2786.  
  2787.     'Set video vbr mode
  2788.     if g_intVideoVBRMode <> -1 then
  2789.         select case g_intVideoVBRMode
  2790.             case 0 ' 1 pass CBR
  2791.  
  2792.             case 1 ' 2 pass CBR
  2793.                 g_objVideoSource.PreProcessPass = 1
  2794.  
  2795.             case 2 ' Quality VBR mode
  2796.                 g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_UNCONSTRAINED
  2797.  
  2798.             case 3 ' 2 pass bitrate based VBR
  2799.                 g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_BITRATE_BASED
  2800.                 g_objVideoSource.PreProcessPass = 1
  2801.  
  2802.             case 4 ' 2 pass bitrate-based peak constrained VBR
  2803.                 g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_PEAK            
  2804.                 g_objVideoSource.PreProcessPass = 1
  2805.  
  2806.             case else
  2807.                 OutputInfo "Invalid -v_mode <mode_number>"
  2808.                 SetupCustomVideoProfile = false
  2809.                 exit function
  2810.  
  2811.         end select
  2812.     end if
  2813.  
  2814.     ' Set video codec
  2815.     if g_strVideoCodec <> "" then
  2816.         intVideoCodecIndex = GetVideoCodecIndex(g_strVideoCodec)
  2817.         intFourCC = g_objProfile.EnumVideoCodec(intVideoCodecIndex, g_strVideoCodecName)
  2818.  
  2819.         objAudience.VideoCodec(0) = intVideoCodecIndex
  2820.     end if
  2821.  
  2822.     if g_intVideoBitrate <> -1 then
  2823.         objAudience.VideoBitrate(0) = g_intVideoBitrate
  2824.     end if
  2825.  
  2826.     if g_intVideoWidth <> -1 then
  2827.         objAudience.VideoWidth(0) = g_intVideoWidth
  2828.     end if
  2829.  
  2830.     if g_intVideoHeight <> -1 then
  2831.         objAudience.VideoHeight(0) = g_intVideoHeight
  2832.     end if
  2833.  
  2834.     if g_intVideoFramerate <> -1 then
  2835.         objAudience.VideoFPS(0) = g_intVideoFramerate
  2836.     end if
  2837.  
  2838.     if g_intVideoKeydist <> -1 then
  2839.         objAudience.VideoKeyFrameDistance(0) = g_intVideoKeydist
  2840.     end if
  2841.  
  2842.     if g_intVideoBuffer <> -1 then
  2843.         objAudience.VideoBufferSize(0) = g_intVideoBuffer
  2844.     end if
  2845.  
  2846.     ' For quality vbr mode use intSmoothness as VBR quality
  2847.     if g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_UNCONSTRAINED then
  2848.         if g_intVideoQuality <> -1 then
  2849.             objAudience.VideoCompressionQuality(0) = g_intVideoQuality
  2850.         end if
  2851.     else
  2852.         if g_intVideoQuality <> -1 then
  2853.             objAudience.VideoImageSharpness(0) = g_intVideoQuality
  2854.         end if
  2855.     end if
  2856.  
  2857.     ' For peak vbr mode set peakbitrate and peak buffer
  2858.     if g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_PEAK then
  2859.         if g_intVideoPeakBuffer <> -1 then
  2860.             objAudience.VideoBufferMax(0) = g_intVideoPeakBuffer
  2861.         end if
  2862.  
  2863.         if g_intVideoPeakBitrate <> -1 then
  2864.             if objAudience.VideoBitrate(0) > g_intVideoPeakBitrate then
  2865.                 objAudience.VideoBitrate(0) = g_intVideoPeakBitrate
  2866.             end if
  2867.             objAudience.VideoPeakBitrate(0) = g_intVideoPeakBitrate
  2868.         end if
  2869.     end if
  2870.  
  2871.     ' Setup video device conformance
  2872.     if g_strVideoDevConf <> "" then
  2873.         objAudience.Property( WMENC_VIDEO, 0, "DeviceConformanceTarget") = g_strVideoDevConf
  2874.     end if
  2875.  
  2876.     SetupCustomVideoProfile = true
  2877. end function
  2878.  
  2879.  
  2880. ' Load the default profile settings
  2881. function LoadProfileDefaults()
  2882.     dim argsArray
  2883.  
  2884.     ' Audio profile settings
  2885.     ' Set default codec and/or VBR mode when appropriate
  2886.     if g_strAudioSetting <> "" then
  2887.         argsArray = Split ( g_strAudioSetting, "_" )
  2888.         if UBound( argsArray ) = 3 and left(g_strAudioSetting, 4) <> "Q100" then
  2889.             g_strAudioCodec = WMA9PRO
  2890.         end if
  2891.     end if
  2892.  
  2893.     if g_intAudioVBRMode = -1 then
  2894.         g_intAudioVBRMode = 0
  2895.     end if
  2896.  
  2897.     if g_strAudioCodec = "" then
  2898.         g_strAudioCodec = "WMA9STD"
  2899.     end if
  2900.  
  2901.     if g_intAudioPeakBuffer = -1 then
  2902.         g_intAudioPeakBuffer = 3000
  2903.     end if
  2904.  
  2905.     ' Set default -a_setting based on format and mode
  2906.     if g_strAudioSetting = "" then
  2907.         if g_intAudioVBRMode = 2 and g_strAudioCodec = WMA9PRO then
  2908.             g_strAudioSetting = "Q75_44_2_24"
  2909.         elseif g_intAudioVBRMode = 2 and g_strAudioCodec = WMA9LSL then
  2910.             g_strAudioSetting = "Q100_44_2_16"
  2911.         elseif g_intAudioVBRMode = 2 then
  2912.             g_strAudioSetting = "Q75_44_2"
  2913.         elseif g_intAudioVBRMode = 0 and g_strAudioCodec = WMSPEECH then
  2914.             g_strAudioSetting = "12_16_1"
  2915.         elseif g_intAudioVBRMode = 0 and g_strAudioCodec = PCM then
  2916.             g_strAudioSetting = "705_22_2"
  2917.         elseif g_strAudioCodec = WMA9PRO then
  2918.             g_strAudioSetting = "128_44_2_24"
  2919.         else
  2920.             g_strAudioSetting = "64_44_2"
  2921.         end if
  2922.     end if
  2923.  
  2924.     ' Video profile settings
  2925.     if g_intVideoVBRMode = -1 then
  2926.         g_intVideoVBRMode = 0
  2927.     end if
  2928.  
  2929.     if g_strVideoCodec = "" then
  2930.         g_strVideoCodec = "WMV9"
  2931.     end if
  2932.  
  2933.     if g_intVideoBitrate = -1 then
  2934.         g_intVideoBitrate = 250000
  2935.     end if
  2936.  
  2937.     if g_intVideoWidth = -1 then
  2938.         g_intVideoWidth = 0
  2939.     end if
  2940.  
  2941.     if g_intVideoHeight = -1 then
  2942.         g_intVideoHeight = 0
  2943.     end if
  2944.  
  2945.     if g_intVideoKeydist = -1 then
  2946.         g_intVideoKeydist = 10000
  2947.     end if
  2948.  
  2949.     if g_intVideoBuffer = -1 then 
  2950.         g_intVideoBuffer = 5000
  2951.     end if
  2952.  
  2953.     if g_intVideoPeakBuffer = -1 then
  2954.         g_intVideoPeakBuffer = 5000
  2955.     end if
  2956.  
  2957.  
  2958.     if g_intVideoPeakBitrate = -1 then
  2959.         g_intVideoPeakBitrate = 1.5 * g_intVideoBitrate
  2960.     end if
  2961.  
  2962.     if g_intVideoQuality = -1 then
  2963.         if g_intVideoVBRMode = 2 then
  2964.             g_intVideoQuality = 95
  2965.         else
  2966.             g_intVideoQuality = 75
  2967.         end if
  2968.     end if
  2969. end function
  2970.  
  2971. ' Setup time configuration
  2972. function SetupTime()
  2973.     if g_blnDevice then
  2974.         ' Duration must be specified when capture from a live device.
  2975.         if g_intDuration = -1 then
  2976.             OutputInfo "Duration must be specified when capturing from devices."
  2977.             SetupTime = false
  2978.             exit function
  2979.         end if
  2980.     end if
  2981.  
  2982.     ' Setup markin and markout
  2983.     if g_intMarkInTime <> -1 then
  2984.         
  2985.         ' Set start time for audio source (mark in) if it has a audio stream.
  2986.         if not IsNull(g_objAudioSource) then
  2987.             g_objAudioSource.MarkIn = g_intMarkInTime
  2988.         end if
  2989.     
  2990.         ' Set start time for video source (mark in) if it has a video stream.
  2991.         if not IsNull(g_objVideoSource) then
  2992.             g_objVideoSource.MarkIn = g_intMarkInTime
  2993.         end if
  2994.     end if
  2995.  
  2996.     ' Is a mark out time provided?
  2997.     if g_intMarkOutTime <> -1 then
  2998.         
  2999.         ' Set end time for audio source (mark out) if it has a audio stream.
  3000.         if not IsNull(g_objAudioSource) then
  3001.             g_objAudioSource.MarkOut = g_intMarkOutTime
  3002.         end if
  3003.         
  3004.         ' Set end time for video source (mark out) if it has a video stream.
  3005.         if not IsNull(g_objVideoSource) then
  3006.             g_objVideoSource.MarkOut = g_intMarkOutTime
  3007.         end if
  3008.     end if
  3009.  
  3010.     SetupTime = true
  3011. end function
  3012.  
  3013. ' Transcode 
  3014. function Transcode()
  3015.     on error resume next
  3016.     
  3017.     ' Prepare to encode
  3018.     g_objEncoder.PrepareToEncode( true )
  3019.  
  3020.     ' Check if we got an error saying markout is greater that end of file. If so set markout to end of file
  3021.     if err.number = -1072882855 then
  3022.         err.Clear
  3023.  
  3024.         if not IsNull(g_objAudioSource) then
  3025.             g_objAudioSource.MarkOut = 0
  3026.         end if
  3027.         
  3028.         if not IsNull(g_objVideoSource) then
  3029.             g_objVideoSource.MarkOut = 0
  3030.         end if
  3031.  
  3032.         g_objEncoder.PrepareToEncode( true )
  3033.     elseif err.number <> 0 then
  3034.         Transcode = false
  3035.         OutputInfo "Prepare to encode failed with error " & err.Number & " " & err.Description
  3036.         exit function
  3037.     end if
  3038.  
  3039.     ' Start encoder
  3040.     g_intErrorCode = 0
  3041.     g_objEncoder.Start()
  3042.     if err.number <> 0 then
  3043.         Transcode = false
  3044.         OutputInfo "Start encoder failed with error " & err.Number & " " & err.Description
  3045.         exit function
  3046.     end if
  3047.  
  3048.     g_tStartTime = Now()
  3049.     
  3050.     ' Wait for start event
  3051.     while not g_blnEncoderStarted and g_intErrorCode = 0
  3052.         WScript.Sleep( 1000 )
  3053.     wend
  3054.  
  3055.     on error goto 0
  3056.     
  3057.     if g_intDuration >= 0 then
  3058.         ' Wait for time
  3059.         OutputInfo "Wait for " & g_intDuration & " seconds to stop encoder..."
  3060.  
  3061.         dim t1, t2
  3062.         
  3063.         t1 = Now()
  3064.  
  3065.         ' Wait until an error code is received
  3066.         do while g_intErrorCode = 0
  3067.             WScript.Sleep( 1000 )
  3068.  
  3069.             t2 = Now()
  3070.  
  3071.             if DateDiff( "s", t1, t2 ) >= g_intDuration then
  3072.                 OutputInfo "Duration time is reached. Stop encoder..."
  3073.                 g_objEncoder.Stop()
  3074.                 exit do
  3075.             end if
  3076.  
  3077.             if g_objEncoder.RunState = WMENC_ENCODER_STOPPED then
  3078.                 OutputInfo "Encoding completed before duration time is reached."
  3079.                 exit do
  3080.             end if
  3081.         loop
  3082.     else
  3083.         ShowProgress
  3084.     end if
  3085.  
  3086.     while not g_blnEncoderStopped and g_intErrorCode = 0
  3087.         WScript.Sleep( 1000 )
  3088.     wend
  3089.  
  3090.     ' Check error event
  3091.     if g_intErrorCode = 0 then
  3092.         OutputInfo "======== Encoding Completed ========"
  3093.         Transcode = true
  3094.     else
  3095.         OutputInfo "Error occurred in transcoding: Error Code = 0x" & Hex( g_intErrorCode )
  3096.         Transcode = false
  3097.     end if
  3098.  
  3099. end function
  3100.  
  3101. ' Show statistics information of output
  3102. function ShowStatistics()
  3103.     dim objProfile
  3104.  
  3105.     ' Output statistics for audio stream
  3106.     if not IsNull(g_objAudioSource) then
  3107.         dim objAudioStats
  3108.         
  3109.         set objAudioStats = g_objEncoder.Statistics.StreamOutputStats( WMENC_AUDIO, 0, 0 )
  3110.  
  3111.         OutputInfo ""
  3112.         OutputInfo "Audio :"
  3113.         OutputInfo vbTab & "Codec: " & g_strAudioCodecName
  3114.         if g_intAudioVBRMode <> 2 then
  3115.             OutputInfo vbTab & "Expected bit rate: " & vbTab & objAudioStats.ExpectedBitrate & " bps"
  3116.         end if
  3117.         OutputInfo vbTab & "Average bit rate: " & vbTab & objAudioStats.AverageBitrate & " bps"
  3118.         OutputInfo vbTab & "Expected sample rate: " & vbTab & objAudioStats.ExpectedSampleRate
  3119.         OutputInfo vbTab & "Average sample rate: " & vbTab & objAudioStats.AverageSampleRate & ""
  3120.         OutputInfo vbTab & "Dropped byte count: " & vbTab & objAudioStats.DroppedByteCount*10000 & " bytes"
  3121.         OutputInfo vbTab & "Dropped sample rate: " & vbTab & objAudioStats.DroppedSampleCount*10000 & ""
  3122.         OutputInfo vbTab & "Total bytes: " & vbTab & vbTab & objAudioStats.ByteCount*10000 & " bytes"
  3123.     end if
  3124.  
  3125.     if not IsNull(g_objVideoSource) then
  3126.         dim objVideoStats
  3127.         
  3128.         set objVideoStats = g_objEncoder.Statistics.StreamOutputStats( WMENC_VIDEO, 0, 0 )
  3129.  
  3130.         OutputInfo ""
  3131.         OutputInfo "Video :"
  3132.         OutputInfo vbTab & "Codec: " & g_strVideoCodecName
  3133.         if g_intVideoVBRMode <> 2 then
  3134.             OutputInfo vbTab & "Expected bit rate: " & vbTab & objVideoStats.ExpectedBitrate & " bps"
  3135.         end if
  3136.         OutputInfo vbTab & "Average bit rate: " & vbTab & objVideoStats.AverageBitrate & " bps"
  3137.         OutputInfo vbTab & "Expected fps: " & vbTab & vbTab & objVideoStats.ExpectedSampleRate / 1000
  3138.         OutputInfo vbTab & "Dropped frame count: " & vbTab & objVideoStats.DroppedSampleCount*10000 & ""
  3139.         OutputInfo vbTab & "Total coded frames: " & vbTab & objVideoStats.SampleCount*10000 & ""
  3140.         OutputInfo vbTab & "Average sample rate: " & vbTab & objVideoStats.AverageSampleRate / 1000 & ""
  3141.         OutputInfo vbTab & "Dropped bytes: " & vbTab & vbTab & objVideoStats.DroppedByteCount*10000 & " bytes"
  3142.         OutputInfo vbTab & "Total bytes: " & vbTab & vbTab & objVideoStats.ByteCount*10000 & " bytes"
  3143.     end if
  3144.  
  3145.     ' Output statistics information of output stream
  3146.     OutputInfo ""
  3147.     OutputInfo "Overall:"
  3148.     OutputInfo vbTab & "Encoding time: " & vbTab & vbTab & DateDiff( "s", g_tStartTime, g_tStopTime ) & " seconds"
  3149.     OutputInfo vbTab & "Average bit rate: " & vbTab & g_objEncoder.Statistics.WMFOutputStats.AverageBitrate & " bps"
  3150.     
  3151.     if g_strOutput <> "" then
  3152.         dim objFileStats
  3153.         
  3154.         set objFileStats = g_objEncoder.Statistics.FileArchiveStats
  3155.     
  3156.         OutputInfo vbTab & "File size: " & vbTab & vbTab & objFileStats.FileSize*10000 & " bytes "
  3157.         OutputInfo vbTab & "File duration: " & vbTab & vbTab & objFileStats.FileDuration*10 & " seconds "
  3158.     end if
  3159.  
  3160. end function
  3161.  
  3162. ' Setup input configuration
  3163. function SetupInput()
  3164.     dim strDeviceName
  3165.  
  3166.     ' The input file name is used if it is not empty, otherwise device index is used.
  3167.     if g_strInput <> "" then
  3168.         dim strInput2
  3169.         
  3170.         strInput2 = g_objFileSystem.GetAbsolutePathName( g_strInput )
  3171.  
  3172.         on error resume next
  3173.  
  3174.         if g_strProfile <> "" then
  3175.             dim strProfileName
  3176.  
  3177.             strProfileName = LCase( g_strProfile )
  3178.             if Left( strProfileName, 1) = "a" and Mid( strProfileName, 2, 1 ) <> "v"  then
  3179.                  g_blnAudioOnly = true
  3180.             elseif Left( strProfileName, 1) = "v" then
  3181.                 g_blnVideoOnly = true
  3182.             end if
  3183.         end if
  3184.  
  3185.         ' Add this file into the source group.
  3186.         if g_blnAudioOnly then
  3187.             set g_objAudioSource = g_objSourceGroup.AddSource( WMENC_AUDIO )
  3188.             g_objAudioSource.SetInput( strInput2 )
  3189.         elseif g_blnVideoOnly then
  3190.             set g_objVideoSource = g_objSourceGroup.AddSource( WMENC_VIDEO )
  3191.             g_objVideoSource.SetInput( strInput2 )
  3192.         else
  3193.             g_objSourceGroup.AutoSetFileSource( strInput2 )
  3194.  
  3195.             ' If source file has an auido stream, get the audio source.
  3196.             if g_objSourceGroup.SourceCount( WMENC_AUDIO ) > 0 then
  3197.                 set g_objAudioSource = g_objSourceGroup.Source( WMENC_AUDIO, 0 )
  3198.             end if
  3199.  
  3200.             ' If source file has a video stream, get the video source.
  3201.             if g_objSourceGroup.SourceCount( WMENC_VIDEO ) > 0 then
  3202.                 set g_objVideoSource = g_objSourceGroup.Source( WMENC_VIDEO, 0 )
  3203.             end if
  3204.  
  3205.         end if
  3206.     elseif g_intAudioDevice <> -1 or g_intVideoDevice <> -1 then
  3207.         if g_intAudioDevice <> -1 then
  3208.             strDeviceName = GetDeviceNameFromIndex( WMENC_AUDIO, g_intAudioDevice )
  3209.             if strDeviceName = "" then
  3210.                 OutputInfo "Error: Invalid audio device number specified" 
  3211.                 SetupInput = false
  3212.                 exit function
  3213.             end if
  3214.             set g_objAudioSource = g_objSourceGroup.AddSource( WMENC_AUDIO )
  3215.             g_objAudioSource.SetInput strDeviceName, "device"
  3216.         end if
  3217.  
  3218.         if g_intVideoDevice <> -1 then
  3219.             strDeviceName = GetDeviceNameFromIndex( WMENC_VIDEO, g_intVideoDevice )
  3220.             if strDeviceName = "" then
  3221.                 OutputInfo "Error: Invalid video device number specified" 
  3222.                 SetupInput = false
  3223.                 exit function
  3224.             end if
  3225.             
  3226.             set g_objVideoSource = g_objSourceGroup.AddSource( WMENC_VIDEO )
  3227.             g_objVideoSource.SetInput strDeviceName, "device"
  3228.         end if
  3229.         
  3230.     end if
  3231.  
  3232.     if g_objSourceGroup.SourceCount( WMENC_AUDIO ) and g_objSourceGroup.SourceCount( WMENC_VIDEO ) then
  3233.         g_intSessionType = WMENC_CONTENT_ONE_AUDIO_ONE_VIDEO
  3234.     elseif g_objSourceGroup.SourceCount( WMENC_AUDIO ) then
  3235.         g_intSessionType = WMENC_CONTENT_ONE_AUDIO
  3236.     elseif g_objSourceGroup.SourceCount( WMENC_VIDEO ) then
  3237.         g_intSessionType = WMENC_CONTENT_ONE_VIDEO
  3238.     end if
  3239.  
  3240.     ' Set audio setting for speech
  3241.     if not IsNull(g_objAudioSource) then
  3242.         SetupAudioSource()
  3243.     end if
  3244.  
  3245.     ' Set video settings
  3246.     if not IsNull(g_objVideoSource) then
  3247.         SetupVideoSource()
  3248.     end if
  3249.    
  3250.     if err.number <> 0 then
  3251.         OutputInfo "Error: 0x" & Hex(err.number) & " - " & err.description
  3252.         err.Clear
  3253.         SetupInput = false
  3254.         exit function
  3255.     end if
  3256.  
  3257.     SetupInput = true
  3258. end function
  3259.  
  3260. 'Set speech related settings on audio source
  3261. function SetupAudioSource()
  3262.     if g_intAudioSpeechContent <> -1 then
  3263.         g_objAudioSource.contentmode = g_intAudioSpeechContent
  3264.     end if
  3265.     if g_strAudioSpeechEdl <> "" then
  3266.         g_objAudioSource.contentedl = g_strAudioSpeechEdl
  3267.     end if
  3268. end function
  3269.  
  3270. 'Set settings on video source
  3271. function SetupVideoSource()
  3272.     ' Set video preprocess
  3273.     select case g_intVideoPreprocess
  3274.         case 0 
  3275.             g_objVideoSource.Optimization = WMENC_VIDEO_STANDARD
  3276.         case 1
  3277.             g_objVideoSource.Optimization = WMENC_VIDEO_DEINTERLACE
  3278.         case 2
  3279.             g_objVideoSource.Optimization = WMENC_VIDEO_DEINTERLACE
  3280.             OutputInfo "Preprocessing mode not supported. Use -height and -width to adjust video size."
  3281.         case 3
  3282.             g_objVideoSource.Optimization = WMENC_VIDEO_DEINTERLACE
  3283.             OutputInfo "Preprocessing mode not supported. Use -height and -width to adjust video size."
  3284.         case 4
  3285.             g_objVideoSource.Optimization = WMENC_VIDEO_DEINTERLACE
  3286.             OutputInfo "Preprocessing mode not supported. Use -height and -width to adjust video size."
  3287.         case 5
  3288.             g_objVideoSource.Optimization = WMENC_VIDEO_INVERSETELECINE
  3289.         case 6
  3290.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_AA_TOP
  3291.         case 7
  3292.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_BB_TOP
  3293.         case 8
  3294.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_BC_TOP
  3295.         case 9
  3296.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_CD_TOP
  3297.         case 10
  3298.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_DD_TOP
  3299.         case 11
  3300.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_AA_BOTTOM
  3301.         case 12
  3302.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_BB_BOTTOM
  3303.         case 13
  3304.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_BC_BOTTOM
  3305.         case 14
  3306.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_CD_BOTTOM
  3307.         case 15
  3308.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_DD_BOTTOM
  3309.         case 16
  3310.             g_objVideoSource.Optimization = WMENC_VIDEO_INTERLACED_AUTO
  3311.         case 17
  3312.             g_objVideoSource.Optimization = WMENC_VIDEO_INTERLACED_TOP_FIRST
  3313.         case 18
  3314.             g_objVideoSource.Optimization = WMENC_VIDEO_INTERLACED_BOTTOM_FIRST
  3315.     end select
  3316.  
  3317.     'Set pixelformat
  3318.     select case ucase( g_strPixelFormat )
  3319.         case "I420"
  3320.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_I420
  3321.         case "IYUV"
  3322.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_IYUV
  3323.         case "RGB24"
  3324.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB24
  3325.         case "RGB32"
  3326.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB32 
  3327.         case "RGB555"
  3328.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB555 
  3329.         case "RGB565"
  3330.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB565
  3331.         case "RGB8"
  3332.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB8
  3333.         case "UYVY"
  3334.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_UYVY
  3335.         case "YUY2"
  3336.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_YUY2
  3337.         case "YV12"
  3338.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_YV12 
  3339.         case "YVU9"
  3340.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_YVU9 
  3341.         case "YVYU"
  3342.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_YVYU 
  3343.     end select
  3344.  
  3345.     'Set pixel aspect ratio
  3346.     if g_intPixelAspectRatioX <> -1 then
  3347.         g_objVideoSource.PixelAspectRatioX = g_intPixelAspectRatioX
  3348.     end if
  3349.  
  3350.     if g_intPixelAspectRatioY <> -1 then
  3351.         g_objVideoSource.PixelAspectRatioY = g_intPixelAspectRatioY
  3352.     end if
  3353.  
  3354.  
  3355.     'Set performance
  3356.     if g_intVideoPerformance <> -1 then
  3357.         g_objEncoder.VideoComplexity = g_intVideoPerformance
  3358.     end if
  3359.  
  3360.     'Set clipping margins
  3361.     if g_intClipLeft <> -1 then
  3362.         g_objVideoSource.CroppingLeftMargin = g_intClipLeft
  3363.     end if
  3364.  
  3365.     if g_intClipRight <> -1 then
  3366.         g_objVideoSource.CroppingRightMargin = g_intClipRight
  3367.     end if
  3368.  
  3369.     if g_intClipTop <> -1 then
  3370.         g_objVideoSource.CroppingTopMargin = g_intClipTop
  3371.     end if
  3372.  
  3373.     if g_intClipBottom <> -1 then
  3374.         g_objVideoSource.CroppingBottomMargin = g_intClipBottom
  3375.     end if
  3376.  
  3377. end function
  3378.  
  3379. 'This function is used to check if the bit rate specified for the a_setting param is valid
  3380. function CheckForValidAudioBitRates( intBitRate )
  3381.  
  3382.     select case intBitRate
  3383.  
  3384.         case 1411200,768000,705600,640000,440000,384000,352800,320000,256000,192000,160000,128000,96000,80000,_
  3385.              64000,48000,40000,32000,22000,20000,17000,16000,12000,10000,8000,6000,5000,4000,0
  3386.             CheckForValidAudioBitRates = True
  3387.  
  3388.         case else
  3389.             CheckForValidAudioBitRates = False
  3390.  
  3391.     end select
  3392. end function
  3393.  
  3394. 'This function is used to check if the sampling rate specified for the a_setting param is valid
  3395. function CheckForValidAudioSamplingRates( intSamplingRate )
  3396.  
  3397.     select case intSamplingRate
  3398.  
  3399.         case 96000,88200,48000,44100,32000,22050,16000,11025,8000
  3400.             CheckForValidAudioSamplingRates = True
  3401.  
  3402.         case else
  3403.             CheckForValidAudioSamplingRates = False
  3404.  
  3405.     end select
  3406. end function
  3407.  
  3408. 'This function is used to check if the channel specified for the a_setting param is valid
  3409. function CheckForValidAudioChannel( intChannel )
  3410.  
  3411.     select case intChannel
  3412.  
  3413.         case 1,2,6,8
  3414.             CheckForValidAudioChannel = True
  3415.  
  3416.         case else
  3417.             CheckForValidAudioChannel = False
  3418.  
  3419.    end select
  3420. end function
  3421.  
  3422. 'This function is used to check if the depth specified for the a_setting param is valid
  3423. function CheckForValidDepth( intAudioDepth )
  3424.  
  3425.     select Case intAudioDepth
  3426.  
  3427.         case 16,20,24
  3428.             CheckForValidDepth = True 
  3429.  
  3430.         case else
  3431.             CheckForValidDepth = False
  3432.  
  3433.    end select 
  3434. end function
  3435.  
  3436. 'This function is the top level function for directory based encoding
  3437. function DoDirectoryModeEncoding()
  3438.     dim strInputFull
  3439.     dim strOutputFull
  3440.  
  3441.     if g_strOutput = "" then
  3442.         OutputInfo "Error: No output directory specified" 
  3443.         DoDirectoryModeEncoding = false
  3444.         exit function
  3445.     end if
  3446.  
  3447.     strInputFull = g_objFileSystem.GetAbsolutePathName(g_strInput)
  3448.     strOutputFull = g_objFileSystem.GetAbsolutePathName(g_strOutput)
  3449.  
  3450.     EncodeFilesInFolder strInputFull, strOutputFull
  3451.  
  3452. end function
  3453.  
  3454. 'This function will create all folders down to the strFolderName level
  3455. function CreateOutputFolder( strFolderName )
  3456.     if g_objFileSystem.FolderExists(strFolderName) = false then
  3457.         CreateOutputFolder( g_objFileSystem.GetParentFolderName( strFolderName ) )
  3458.         g_objFileSystem.CreateFolder( strFolderName )
  3459.         end if
  3460. end function
  3461.  
  3462. 'This function will encode all files in the input directory and generate output files in output directory
  3463. function EncodeFilesInFolder( strInputFolderName, strOutputFolderName )
  3464.     dim objSubFoldersCollection
  3465.     dim objInputSubFolder
  3466.     dim strOutputSubFolderName, strFileType
  3467.     dim objFile, objFolder, objFileCollection
  3468.  
  3469.     OutputInfo "============== Encoding Files in Folder ============== " & strInputFolderName
  3470.  
  3471.     set objFolder = g_objFileSystem.GetFolder( strInputFolderName )
  3472.     
  3473.     ' First encode all the files contained in the input folder
  3474.     set objFileCollection = objFolder.Files
  3475.  
  3476.     for each objFile in objFileCollection
  3477.  
  3478.         strFileType = right(objFile.name, len(objFile.name) - instrrev(objFile.name,".") )  
  3479.  
  3480.         select case lcase(strFileType)
  3481.             case "avi", "wav", "mpg", "mpeg", "vob" , "wmv" , "wma", "mp3", "asf"
  3482.                 g_strInput = strInputFolderName & "\" & objFile.name
  3483.                 g_strOutput = strOutputFolderName & "\" & Left(objFile.name, len(objFile.Name)-(len(objFile.name) - instrrev(objFile.name,".") + 1)) & g_strOutputString
  3484.  
  3485.                 OutputInfo "============== Input " & g_strInput & " " & g_strOutput
  3486.  
  3487.                 ' This will force wmcmd to append wmv/wma extension
  3488.                 g_strOutput = g_strOutput & "."
  3489.             
  3490.                 ' Encode files
  3491.                 if SetupEncoder() then
  3492.                     if Transcode() and not g_blnSilent then 
  3493.                         ShowStatistics()
  3494.                     end if 
  3495.                 end if
  3496.  
  3497.                 ' reset encoder states for next file 
  3498.                 g_objEncoder.PrepareToEncode( false )
  3499.                 g_objEncoder.SourceGroupCollection.Remove( "SG_1" )
  3500.                 g_objSourceGroup = Null
  3501.                 g_objAudioSource = Null
  3502.                 g_objVideoSource = Null
  3503.                 g_blnEncoderStarted = false
  3504.                 g_blnEncoderStopped = false
  3505.                 g_blnEndPreProcess = false
  3506.  
  3507.             case else
  3508.                 OutputInfo "Skipping: " & objFile.name
  3509.         end select
  3510.     next
  3511.  
  3512.     ' Then recurse into subfolders and encode all files there
  3513.     set objSubFoldersCollection = objFolder.SubFolders
  3514.  
  3515.     for each objInputSubFolder in objSubFoldersCollection
  3516.         strOutputSubFolderName = strOutputFolderName & "\" & objInputSubFolder.name
  3517.  
  3518.         EncodeFilesInFolder objInputSubFolder, strOutputSubFolderName
  3519.     Next
  3520.  
  3521. end function
  3522.  
  3523. ' Get device name from index
  3524. function GetDeviceNameFromIndex(enumMediaType, intDeviceIndex)
  3525.     dim intLastDevice
  3526.     dim objSourceInfo, objSourcePluginManager
  3527.  
  3528.     intLastDevice = 0
  3529.     set objSourcePlugInManager = g_objEncoder.SourcePlugInInfoManager
  3530.  
  3531.     for i = 0 to objSourcePlugInManager.count -1
  3532.         set objSourceInfo = objSourcePlugInManager.Item(i)
  3533.         
  3534.         if objSourceInfo.Resources = true then
  3535.             if enumMediaType = WMENC_AUDIO then ' Audio
  3536.                 ' For audio search audio and audio | video
  3537.                 if objSourceInfo.MediaType = 1 or objSourceInfo.MediaType = 3 then
  3538.                     if intDeviceIndex < intLastDevice + objSourceInfo.Count then
  3539.                         GetDeviceNameFromIndex = objSourceInfo( intDeviceIndex - intLastDevice )
  3540.                         exit function
  3541.                     else 
  3542.                         intLastDevice = intLastDevice + objSourceInfo.Count
  3543.                     end if
  3544.                 end if
  3545.             else ' Video
  3546.                 ' For video search video, audio | video and video | script
  3547.                 if objSourceInfo.MediaType = 2 or objSourceInfo.MediaType = 3 or objSourceInfo.MediaType = 6 then
  3548.                     if intDeviceIndex < intLastDevice + objSourceInfo.Count Then
  3549.                         GetDeviceNameFromIndex = objSourceInfo( intDeviceIndex - intLastDevice )
  3550.                         exit function
  3551.                     else 
  3552.                         intLastDevice = intLastDevice + objSourceInfo.Count
  3553.                     end if
  3554.                 end if
  3555.             end if
  3556.         end if
  3557.     next
  3558.  
  3559.     GetDeviceNameFromIndex = ""
  3560.  
  3561. end function
  3562.  
  3563. function ShowProgress()
  3564.     dim intSleepDuration, intPercent, intADuration, intVDuration, intDuration
  3565.     dim intPasses, intLimit
  3566.  
  3567.     ' Display metadata information passed to the encoder script
  3568.  
  3569.     OutputInfo "Microsoft Windows Media Encoder 9 Series"
  3570.     OutputInfo " "
  3571.     OutputInfo " "
  3572.     OutputInfo "Title:     " & g_strTitle
  3573.     OutputInfo "Track No:  " & g_intTrackNo
  3574.     OutputInfo "Artist:    " & g_strAuthor
  3575.     OutputInfo "Album:     " & g_strAlbum
  3576.     OutputInfo "Year:      " & g_strYear
  3577.     OutputInfo "Genre:     " & g_strGenre
  3578.     OutputInfo "Copyright: " & g_strCopyright
  3579.     OutputInfo "Comment:   " & g_strDescription
  3580.     OutputInfo " "
  3581.     OutputInfo " "
  3582.  
  3583.     intPasses = 1
  3584.  
  3585.     ' Compute number of passes required
  3586.     if not IsNull(g_objAudioSource) then
  3587.         if g_objAudioSource.PreProcessPass = 1 then
  3588.             intPasses = 2
  3589.         end if
  3590.     end if
  3591.  
  3592.     if not IsNull(g_objVideoSource) then
  3593.         if g_objVideoSource.PreProcessPass = 1 then
  3594.             intPasses = 2
  3595.         end if
  3596.     end if
  3597.  
  3598.     ' Compute file duration
  3599.     if not IsNull(g_objAudioSource) then
  3600.         if g_objAudioSource.MarkOut <> 0 then
  3601.             intADuration = g_objAudioSource.MarkOut - g_objAudioSource.MarkIn
  3602.         else
  3603.             intADuration = g_objAudioSource.Duration - g_objAudioSource.MarkIn
  3604.         end if
  3605.     end if
  3606.     if not IsNull(g_objVideoSource) then
  3607.         if g_objVideoSource.MarkOut <> 0 then
  3608.             intVDuration = g_objVideoSource.MarkOut - g_objVideoSource.MarkIn
  3609.         else
  3610.             intVDuration = g_objVideoSource.Duration - g_objVideoSource.MarkIn
  3611.         end if
  3612.     end if
  3613.  
  3614.     if intADuration > intVDuration then
  3615.         intDuration = intADuration
  3616.     else
  3617.         intDuration = intVDuration
  3618.     end if
  3619.  
  3620.     intSleepDuration = 2000
  3621.     
  3622.     ' For all passes show progress from 0 to 100
  3623.     for j=0 to intPasses-1
  3624.         intPercent = 0
  3625.  
  3626.         if intPasses = 2 and j = 0 then
  3627.             OutputInfo "======== Begin Pass1 ========"
  3628.         elseif intPasses = 2 and j = 1 then
  3629.             OutputInfo "======== Begin Pass2 ========"
  3630.         end if
  3631.     
  3632.         for i=1 to 4
  3633.             intLimit = 25 * i
  3634.             do while g_objEncoder.RunState <> WMENC_ENCODER_STOPPED and g_intErrorCode = 0 and intPercent < intLimit
  3635.                 WScript.stdout.Write "."
  3636.                 WScript.Sleep intSleepDuration
  3637.                 if intDuration <> 0 then
  3638.                     intPercent = Int( g_objEncoder.Statistics.EncodingTime * 1000000 / intDuration )
  3639.                 end if
  3640.                 if intPasses = 2 and j = 0 and intLimit = 100 and intPercent < 75 then
  3641.                     ' second pass has already started
  3642.                     exit Do
  3643.                 end if
  3644.             loop
  3645.         
  3646.             ' Only show progress if we know the duration of source files
  3647.             if intDuration <> 0 and g_intErrorCode = 0 then
  3648.                 WScript.stdout.Write intLimit &"%."
  3649.             end if
  3650.  
  3651.             if g_intErrorCode <> 0 then 
  3652.                 exit for
  3653.             end if
  3654.         next
  3655.  
  3656.         if j = 0 and intPasses = 2 then
  3657.             do while not g_blnEndPreProcess and g_intErrorCode = 0
  3658.                 WScript.Sleep intSleepDuration
  3659.             loop
  3660.         end if
  3661.  
  3662.         if g_intErrorCode <> 0 then 
  3663.             exit for
  3664.         end if
  3665.  
  3666.         OutputInfo ""
  3667.     next
  3668.  
  3669. end function
  3670.